0

I have this formula in REGEX Google Sheets:

=REGEXREPLACE(P74, "\s*(\d*)\s*(?:(B)O(T)T(L)E OF|(T)A(B)LET|(C)APLE(T)|(CAP)SULE|(AMP)OULE|(S)ACHE(T)|(A)P(P)(L)ICATOR(B)OT(T)(L)E OF|(BL)ISTER|(V)IA(L)|3.5 MG|(ALUMINIUM/ALUMINIUM)|[()]|@|OF)", "$1$2$3$4$5$6$7$8$9$10")

And i have this data in many rows:

BX-5VL @ 6 ML
BX-5VL @ 8 ML
BX-5VL @ 15 ML

I would like to simply remove all numbers for and ML attached to return like this:

BX-5VL 
BX-5VL 
BX-5VL 
0

3 Answers 3

1

You may replace the following regex pattern with empty string:

\s*@\s+\d+\s+ML$

Sample code:

=REGEXREPLACE(
     REGEXREPLACE(P74, "your current regex", "$1$2$3$4$5$6$7$8$9$10"),
     "\s*@\s+\d+\s+ML$",
     ""
)

Demo

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your help i dont get it how i can put that command twice in the formula : =REGEXREPLACE(P2, "\s*(\d*)\s*(?:(B)O(T)T(L)E OF|"\s*@\s+\d+\s+ML$", ""|(T)A(B)LET|(C)APLE(T)|(CAP)SULE|(AMP)OULE|(S)ACHE(T)|(A)P(P)(L)ICATOR|(SUP)POSITORY|(B)OT(T)(L)E OF|(E)(F)FERVESCENT|(BL)ISTER|(V)IA(L)|3.5 MG|(ALUMINIUM/ALUMINIUM)|[()]|@|OF)", "$1$2$3$4$5$6$7$8$9$10")
Oh...didn't know you wanted this as part of your original formula. The easiest thing to do here might be to just wrap your current formula. Check my updated answer.
Sometimes it's nice to have a single regex for all requirements, and sometimes it is ugly. I'm leaning towards the latter in this case.
still dont work for some reason : =REGEXREPLACE( REGEXREPLACE(P2, "\s*(\d*)\s*(?:(B)O(T)T(L)E OF|(T)A(B)LET|(C)APLE(T)|(CAP)SULE|(AMP)OULE|(S)ACHE(T)|(A)P(P)(L)ICATOR|(SUP)POSITORY|(B)OT(T)(L)E OF|(E)(F)FERVESCENT|(BL)ISTER|(V)IA(L)|3.5 MG|(ALUMINIUM/ALUMINIUM)|[()]|@|OF)", "$1$2$3$4$5$6$7$8$9$10"), "\s*@\s+\d+\s+ML$", "" )
You may also try: REGEXREPLACE(P74, "^(.*)\s*@\s+\d+\s+ML$", "$1") ... I don't know the quirks of this API, the current regex works in the demo and should also be working here.
1

all you need:

=INDEX(IFERROR(SPLIT(A1:A, "@")),,1)

enter image description here

or:

=ARRAYFORMULA(TRIM(REGEXREPLACE(A1:A, "@? \d+ ML$", )))

0

1 Comment

Yes it works thanks, but i have to replace so many things like in my formula. I will have to create many columns
0

Hope this help you

function removeAccents() {
  var spreadsheet = SpreadsheetApp.getActive();
  var range = spreadsheet.getRange("F3:F");
  var data  = range.getValues();

  for (var row = 0; row < data.length; row++) {
    for (var col = 0; col < data[row].length; col++) {
      data[row][col] = (data[row][col]).toString().replace(/á|à|ã|ä}/g, 'a');
      data[row][col] = (data[row][col]).toString().replace(/é|ë|ê/g, 'e');
      data[row][col] = (data[row][col]).toString().replace(/í|ì|î/g, 'i');
      data[row][col] = (data[row][col]).toString().replace(/ó|ò|õ|ô/g, 'o');
      data[row][col] = (data[row][col]).toString().replace(/ú|ù|û/g, 'u');
      data[row][col] = (data[row][col]).toString().replace(/ç/g, 'c');
      data[row][col] = (data[row][col]).toString().replace(/[|]|\/|\\|\|/g, '-');
    }
  }
  range.setValues(data);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.