Reputation: 11
I have cell B10 with text that contains slashes and I want to extract the text around those slashes.
Example: Text in B10 is PV AA/BB 1250/2500/13
and I want to extract 1250/2500
in cell O10.
I tried to do =REGEXEXTRACT(B10, "([1-9][0-9][0-9][0-9])\/([1-9][0-9][0-9][0-9])")
but for some reason, this splits the result into two cells (O10 and O11), without the /. Similar happens when I try to extract the AA/BB
with ([a-zA-Z]+)\/([a-zA-Z]+)
- it returns AA
and BB
in two separate cells.
What is happening here? How do I extract the string into one cell only, with the slash?
Upvotes: 1
Views: 877
Reputation: 163362
You can 2 capture groups, but for a match you don't need any groups, and the /
also does not have to be escaped.
=REGEXEXTRACT(B10, "[1-9]\d{3}/[1-9]\d{3}")
Or use REGEXREPLACE
with the 2 capture groups and the /
in the replacement and matching all chars before and after it so that they won't be present after the replacement.
=REGEXREPLACE(B10, ".*([1-9]\d{3})/([1-9]\d{3}).*", "$1/$2")
Upvotes: 0
Reputation: 1
try:
=REGEXEXTRACT(B10; "\d{4}.\d{4}")
or:
=REGEXEXTRACT(B10; " (\d+.\d+)")
Upvotes: 0
Reputation: 51
you have extra brackets "()" in your regular expression it should be,
=REGEXEXTRACT(B10, "([1-9][0-9][0-9][0-9]\/[1-9][0-9][0-9][0-9])")
the brackets ")(" before and after / is removed to get the desired result
Upvotes: 1