Page 1 of 1

Regex again (string between first and last underscore)

Posted: Mon Jun 14, 2021 8:56 am
by magnussandstrom
Hi, in a Switch variable I would like to capture the string between the first and last underscore, without including the underscores. But since switch don't support lookahead/lookbehind (or groups?) I would need som help.

Original string: 1234abc_This_is_the_text_I_want_1234abc

I want the result: This_is_the_text_I_want

But with _(.*)_ I get the result: _This_is_the_text_I_want _

I would like to use (?<=\_)(.*?)(?=\_) but thats not supported.

Any suggestions?

Re: Regex again (string between first and last underscore)

Posted: Mon Jun 14, 2021 11:19 am
by freddyp

Re: Regex again (string between first and last underscore)

Posted: Mon Jun 14, 2021 1:03 pm
by magnussandstrom
I tried the stringsplitter app but it devides the string in separate parts devided by underscore (in this case), but I don't want to separate the middle section (after the first underscore til the last underscore) if it also contains underscores.

Re: Regex again (string between first and last underscore)

Posted: Mon Jun 14, 2021 1:07 pm
by magnussandstrom
A regex app that can fully utilise regular expression functions would be great! Ping @appdevs :) Unless it's added in a future Switch release.

Re: Regex again (string between first and last underscore)

Posted: Mon Jun 14, 2021 3:04 pm
by Arthur
It has been queried many times over since at least 2017 release of Switch, yet seemingly not enough needed, since it has not been implemented in full yet.
They know of this being useful to have full Regex in Switch, but it is not easy to get it implemented apparently. I mean, this is what I was told in 2019 in London on one of the Enfocus days or whatever it was called.
I am guessing - the more voices behind this, the more likely they will be looking into it.