I am using Tableau to create a visualization and need to apply Regex to string values in my data set. I'm trying to use Regex to return the nth match of this string of data: b29f3b2f2b2f3b3f1r2f3+b3x#. The data will always be in one line and I need to break the data out into substrings each time the characters b,s,f, or d are encountered and I need to match the nth occurrence returned. For example, when identifying which number match to return the following will match:
I can get the n=1 match to return the proper value using bfsd(?=[bfsd]) and have tried to get the subsequent values to return using lookahead, but can't find a regex which works. Any help is appreciated.
Your item pattern is [bfsd][^bfsd]*
.
You may use ^(?:.*?([bfsd][^bfsd]*)){n}
to get what you need, just update the n
variable with the number you need to get.
This pattern will get you the second value:
^(?:.*?([bfsd][^bfsd]*)){2}
See regex demo.
Details
^
- start of string(?:.*?([bfsd][^bfsd]*)){2}
- two occurrences of
.*?
- any 0+ chars, as few as possible([bfsd][^bfsd]*)
- b
, f
, s
or d
followed with 0+ chars othet than b
, f
, s
and d
.