Reputation: 55
Using Regex, I'm attempting to get back the following (stars denote what I'd like to extract) from each string using a single Regex command:
FO4H56FD-BTU (Follow Home 56): PLTD8
\***********
FO4H56FD-SYH-BI (Follow Home 56 SYH): PLTD8
\***********
FO4H52FD-SZH-AG4R-BI (Follow Home 52 SAH): QQTD8
\****************
FO4H58FD-SGH: (Follow Home 58 TGT): PLTS8
\***********
For some reason I'm having a lot of difficulties. I've been using various methods and currently have =REGEXEXTRACT(A43,"(FO.+)\-BI")
which isn't working. Mine also isn't looking for the :
currently. I was using a |
for multiple rules which didn't seem to work out.
Upvotes: 1
Views: 99
Reputation: 626927
You may use
=REGEXEXTRACT(A43,"^(.*?)(?:-BI)?(?:[ :]|$)")
Details:
^
- start of string(.*?)
- capturing group #1 matching any 0+ chars as few as possible(?:-BI)?
- an optional non-capturing group matching 1 or 0 occurrences of -BI
substring(?:[ :]|$)
- either a space, :
or end of stringUpvotes: 2