Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match regex up to first space

Tags:

regex

I have to populate a shop's images and been provided with folders of images which arein the format, eg BRL0368 Side.jpg, 5510 Dura Guard Carpet.jpg.

Now what I want to do is chop all those down so I can just try and match up in excel the part numbers eg "BRL0368.jpg", "5510.jpg"

I have something called regex renamer which takes a regex match & a replacement value - and will recurse through a folder etc and batch rename.

Unfortunately at the moment I don't have much expereince with regex so it's a bit confusing for me - I tried many different options but not having much luck.

How do I say grab the first part (alpha & digit) up to the first space and dump the rest?

this is what I have been trying ([^\s]+) - I also tried \w etc.

like image 522
mro Avatar asked Dec 27 '22 03:12

mro


1 Answers

It may depend on the language used, but this should work :

/^[^\s]+/

To capture the first word and the last (the extension) you can use this expression :

/(^[^\s]+).*?(\.\w+)$/

Here's a javascript demo to clear things up : http://jsfiddle.net/eDB2z/1/

like image 172
gion_13 Avatar answered Jan 08 '23 18:01

gion_13