Reg Ex help

Post Reply
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Reg Ex help

Post 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?
User avatar
JimmyHartington
Advanced member
Posts: 279
Joined: Tue Mar 22, 2011 7:38 am

Re: Reg Ex help

Post 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
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Reg Ex help

Post by Terkelsen »

Thanks a lot, Jimmy. Works perfect ;)
User avatar
JimmyHartington
Advanced member
Posts: 279
Joined: Tue Mar 22, 2011 7:38 am

Re: Reg Ex help

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