Page 1 of 1

Reg Ex help

Posted: Mon May 06, 2019 8:18 am
by Terkelsen
I could use a little help with a regular expression.

The string I'm searching looks like this: "word1 word2 word3Number_number_1234". I need everything until (but NOT including) the last underscore.

This regEx
.*\_
will give me everything until and including the last underscore "word1 word2 word3Number_number_". How can I get rid of the last underscore?

Re: Reg Ex help

Posted: Mon May 06, 2019 8:26 am
by JimmyHartington
Hi Erik

I think you need to look into Lookahead and Lookbehind in RegEx.

I used a Lookahead in this test and it does the job. But I am not that strong in RegEx to say this is the best solution.
Image

Read more here:
https://www.rexegg.com/regex-lookarounds.html

Re: Reg Ex help

Posted: Mon May 06, 2019 8:55 am
by Terkelsen
Thanks a lot, Jimmy. Works perfect ;)

Re: Reg Ex help

Posted: Mon May 06, 2019 9:00 am
by JimmyHartington
Your welcome.

This trick is also good in InDesign as grep style to upper digits in m2 m3 og sup in CO2 and the like.