Skip to main content
Participant
Sep 25, 2025 10:44 AM UTC
Answered

String sub regex help

Hi! I'm trying to rename a batch of images named similar to the following:

  • POS1112_SS26_PHONE_170X300MM.jpg
  • POS1118_SS26_ARCH_170X300MM.jpg

It's a mix of JPGs and tiffs but they all follow the same layout as above. I only want to remove everything after the first underscore to leave them as-

  • POS1112
  • POS1118

I'm aware of regex but sadly don't have a clue where to start with it. 

Thanks in advance!

Stephen Marsh
Stephen MarshCorrect answer
Community Expert
Sep 25, 2025 11:33 AM UTC

Option 1: Find, Replace with nothing -

 

_[\s\S]*

 

 

Option 2: Capture group find/replace -

 

^(.*?)_.*

 

$1

 

3 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
Sep 25, 2025 11:33 AM UTC

Option 1: Find, Replace with nothing -

 

_[\s\S]*

 

 

Option 2: Capture group find/replace -

 

^(.*?)_.*

 

$1

 

Translate
Participant
Sep 25, 2025 12:06 PM UTC

Worked! Thank you!

Translate
Stephen Marsh
Community Expert
Community Expert
Sep 25, 2025 8:09 PM UTC

You're welcome!

Translate