Home > Software design >  Spreadsheet RegexReplace but exclude non-number
Spreadsheet RegexReplace but exclude non-number

Time:04-26

How to RegexReplace but only for number.

enter image description here


I tried this formula, but it didn't go as I expected:
=REGEXREPLACE(A2, ":<BR CLASS="""">[0-9]", ": [0-9]")

This is the sheet link:
https://docs.google.com/spreadsheets/d/1j6X0YtpTz9pnwa9woR-Q1tkStSaCfmQ67f11PiBwLBM/edit#gid=0

Thanks for your help, i really appreciate it.

CodePudding user response:

You can use \d (or [0-9] ) to match one or more digits, and a capturing group (a pair of unescaped parentheses) around the pattern you want to keep, with a backreference to the group value in the replacement:

=REGEXREPLACE(A2, ":<BR CLASS="""">(\d )", ": $1")

enter image description here

Details:

  • :<BR CLASS= - a fixed string
  • """" - a "" pattern (since a " char should be escaped with another " in a string literal in Google Sheets formula)
  • > - a > char
  • (\d ) - Capturing group 1 ($1 refers to the group value): one or more digits.
  • Related