匹配正则表达式到第一个空格

时间:2021-09-15 23:40:08

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.

我必须填充一个商店的图像,并提供了格式的图像文件夹,例如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"

现在我要做的就是砍掉所有这些,这样我就可以尝试在excel中匹配部件号,例如“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.

我有一个名为regex renamer的东西,它采用正则表达式匹配和替换值 - 并将通过文件夹等进行递归并批量重命名。

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.

这是我一直在尝试的([^ \ s] +) - 我也试过\ w等。

2 个解决方案

#1


8  

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/

这是一个javascript演示来清理:http://jsfiddle.net/eDB2z/1/

#2


1  

This is what you need: \w*(?= )

这就是你需要的:\ w *(?=)

#1


8  

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/

这是一个javascript演示来清理:http://jsfiddle.net/eDB2z/1/

#2


1  

This is what you need: \w*(?= )

这就是你需要的:\ w *(?=)