Hello,
I have a list of strings with an underscore seperator like the following:
ftThreefinalgrps_brd4_co10
ftif5_co10
ftqn5_bra1
I also have a list of "identifiers", that tell me what each part of the string means.
please note that the number of identifiers and their name is variable
br
ft
co
The goal is to parse the string using the identifiers.
Using my first variable, I want to find everything after "br" and before the underscore (if there is any), in this case "d4".
Then I want everything after "ft" and before the underscore, being "Threefinalgrps"
Finally, I want everything after co and before the underscore, so "10"
My ideal final result would be:
variable | ft | br | co |
ftThreefinalgrps_brd4_co10 | Threefinalgrps | d4 | 10 |
ftif5_co10 | if5 | 10 | |
ftqn5_bra1 | qn5 | a1 |
Does anyone have a suggestion on how to start?
Thanks!
Mikis
Solved! Go to Solution.
I think I got it :)
Could it be that
?=
should have been
?:
I changed it to the below, and it seems to be working (even though I don't know why, I just read that an umarked group was defined by (?: ) and I somehow think you're doing that?
REGEX_Replace( [variables], ".*?((?:^|_)" + [dimensions] + "([^_]+))?.*?", "$2")
No I was trying to do a look behind but lets make it simpler:
REGEX_Replace( "_" + [variables], ".*?_(" + [Field1] + "([^_]+))?.*?", "$2")
This requires an _ before the field name and then gets around the start by just prefixing the string!
My quick check seems to show this should work
Hm, now everything seems to Match (only the real match removes the dimension prefix).
i do understand what you're trying to do and it's really resourceful
But my above formula does what I was hoping for, do you think there are issues to it?
Yep, yours should work perfectly.
Adjusted mine and think it should work as well finally!
REGEX_Replace( "_" + [variables], ".*?((?<=_)" + [Field1] + "([^_]+))?.*?", "$2")
Works like a charm!