Essentially there are strings of text and I am trying to pull out a single value/word that starts with one of two values. Two examples would be:
Just example text here 91291-99 that can continue after
Or it could be X1234-81 and after
In these examples I would want 91291-99 or X1234-81 to be pulled out into a different column based on starting with a 9 or an X.
I suspect a RegEx equation could do it but I can't figure out how.
Solved! Go to Solution.
@tprue If the text you want to pull out each time is going to be five characters then a hyphen then two numbers, you can use this expression in a RegEx tool with the Parse function: .*\s(.{5}\-\d{2}).*
Thanks! That almost works, but there could be other values following that same format in the same text string that don't start with a 9 or an X that I would want to exclude. Sorry I left that detail out before For instance:
62222-10 is in the same string as 91239-09 and I would only want the second value
@tprue I made the changes to the data and added some of my own. I used two RegEx tools, one with each of these expressions:
.*\s([X].{4}\-\d{2}).*
.*\s(\d{5}\-\d{2}).*
Then I unioned them and filtered out any nulls.
If there are other conditions that you find along the way, go check out www.regex101.com. It's super helpful in learning RegEx.
@tprue I also thought maybe you could use the Tokenize function of the RegEx tool and filter out what you don't want after that. The expression I used for Tokenize was this: .{5}\-\d{2}
This expression captures any five characters in a row followed by a "-" and followed by exactly 2 digits. The Filter tool after that only allows records to pass if they start with either "X" or "9." There's probably an easier way to do it, but here's the screenshot for that.
This one worked, and thanks for the suggestion of where to learn more about RegEx!