Skip to main content
Participant
September 25, 2025
Answered

String sub regex help

  • September 25, 2025
  • 1 reply
  • 149 views

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!

Correct answer Stephen Marsh

Option 1: Find, Replace with nothing -

 

_[\s\S]*

 

 

Option 2: Capture group find/replace -

 

^(.*?)_.*

 

$1

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
September 25, 2025

Option 1: Find, Replace with nothing -

 

_[\s\S]*

 

 

Option 2: Capture group find/replace -

 

^(.*?)_.*

 

$1

 

Participant
September 25, 2025

Worked! Thank you!

Stephen Marsh
Community Expert
Community Expert
September 25, 2025

You're welcome!