Regex again (string between first and last underscore)

Post Reply
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Regex again (string between first and last underscore)

Post 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?
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

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

Post by freddyp »

User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

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

Post 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.
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

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

Post 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.
Arthur
Member
Posts: 113
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

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

Post 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.
Post Reply