-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
  • 124,011
  • 12
  • 67
  • 124
Simon GIS
  • 1,045
  • 2
  • 18
  • 37

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
  • 70,606
  • 8
  • 39
  • 70
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
  • 5,964
  • 2
  • 22
  • 34