-1

I have this data in Google sheets Or Excel:

2 MG/ML
500 MCG
100 MG ; 200 MG ; 200 MCG
100 MCG/ML
325 MG ; 37.5 MG
60 G ; 9 G/1000 ML

I would like to have it this format. i think Regex expression could do? How i Can acheive that?:

all data                       Dose                Unit 
2 MG/ML                          2                 MG/ML
500 MCG                         500                MCG
100 MG ; 200 MG ; 200 MCG       100;200;200        MG;MG;MCG
100 MCG/ML                      100                MCG/ML
325 MG ; 37.5 MG                325;37.5           MG;MG
60 G ; 9 G/1000 ML              60;9               G;G/1000 ML
player0
  • 69,261
  • 8
  • 33
  • 67
Simon GIS
  • 709
  • 9
  • 21

2 Answers2

3

In B2 you could use:

=REGEXREPLACE(A2,"(;)?(?:^| +)([\d.]+)[ A-Z\/\d]+","$1$2")

See the online demo

In C2 you could use:

=REGEXREPLACE(A2,"(?:^|\s*(;))\s*[\d.]+\s*","$1")

See the online demo

Drag both down.

enter image description here

JvdV
  • 41,931
  • 5
  • 24
  • 46
2

@JvdV has come up with a great solution. Another way to solve this is to make your own custom functions with Google Apps Script, in case you need more flexibility down the line:

function GETDIGITS(inputString) {
  return inputString.toString().match(/(?<=^|\s)([\d.]+)(?=\s|$)/g).join(";");
}

function GETUNITS(inputString) {
  return inputString.toString().split(";").map(str => str.match(/[A-Z]+(\/[A-Z0-9\s]+)?/g)).join(";");
}

Demo

jdaz
  • 4,794
  • 2
  • 16
  • 27