Search code examples
regexgoogle-sheetsgoogle-sheets-formularegexp-replace

Google Sheets Regex removing unnecessary text


Please help me to solve this problem.

Using below formula to extract this information.

IFERROR(REGEXEXTRACT(A2:A,"(TRN\*.+\\|TRN\*.+\~)"))

I want to remove these signs from output \ and ~.

Here is the formula output.

TRN*1*6523251452*5865418282584~
TRN*1*5685952452*158615*6526352 26\

Solution

  • You can use

    IFERROR(REGEXEXTRACT(A2:A,"TRN\*[^~\\]+"))
    

    See the regex demo. Also, you may add a word boundary \b at the start of the pattern to make sure TRN is matched as a whole, standalone word, \bTRN\*[^~\\]+.

    Details

    • TRN\* - TRN* text
    • [^~\\]+ - one or more chars other than ~ and \.