For an example I have a value like this:
"ConFst-DxtExBS1-NtrB1".
This is the regular expression I used to extract the value between '-' that is "DxtExBS1":
-(.*?)-
Now I want to write a regular expression that should extract the values after the 2nd repeated '-', that is "NtrB1". I cannot say 1-(.*?)$
because the digit is not static. But the pattern will not change.
I think I only need to tell:
begin after 2nd one hyphen then
(.*?)$
CodePudding user response:
Do this:
"-[^-\s]*-([^-\s]*)"
We essentially match every non-whitespace character which is not a -
until the second -
is encountered, then capture the rest until yet another -
may or may not appear.
The captured group will have the text present after the second -
.
As per your comments, you can use this:
-[^-]*-(.*)
This matches until the second -
, then captures the rest.
CodePudding user response:
You may try the following regex pattern:
=REGEXP_EXTRACT("ConFst-DxtExBS1-NtrB1", "[^-] $")