Home > Back-end >  Unsure how to NOT include a match in REGEXREPLACE
Unsure how to NOT include a match in REGEXREPLACE

Time:04-28

How do I turn Bay 13 | Brand PS/CPP into 13 using REGEXREPLACE in Google Sheets? I can't figure out how to NOT include a pattern, as it seems whatever I type as the pattern it takes it out completely. I'm not used to this behavior in REGEX.

For instance:

REGEXREPLACE("(?i)bay ", )

returns 13 | Brand PS/CPP. I want to keep the 13 (which could be any number between 1-35 including halves (12.5)), and get rid of everything after it including the "|" pipe.

CodePudding user response:

try "everything after bay and before a pipe":

=REGEXEXTRACT(A1, "(?i)bay (. ) \|")

enter image description here

or if you want specifics:

=REGEXEXTRACT(A1, "(?i)bay (\d (?:\.\d )?) \|")

enter image description here

CodePudding user response:

I think you want to use REGEXEXTRACT here rather than REGEXREPLACE:

REGEXEXTRACT("\d (?:\.\d )?", "Bay 13 | Brand PS/CPP")
  • Related