正则表达式查找单个qoutes之间的空间并替换为下划线 [英] Regex Find Spaces between single qoutes and replace with underscore
问题描述
我有一个已导出的数据库表.我需要用空格替换图像文件名,并想使用notepad ++和regex这样做.我有:
I have a database table that I have exported. I need to replace the image file name with a space and would like to use notepad++ and regex to do so. I have:
'data/green tea powder.jpg'
'data/prod_img/lumina herbal shampoo.JPG'
'data/ALL GREEN HERBS.jpeg'
'data/prod_img/PSORIASIS KIT (640x530) (2).jpg'
并且需要使它们看起来像这样:
and need to make them look like this:
'data/green_tea_powder.jpg'
'data/prod_img/lumina_herbal_shampoo.JPG'
'data/ALL_GREEN_HERBS.jpeg'
'data/prod_img/PSORIASIS_KIT_(640x530)_(2).jpg'
我只想更改引号之间的空格(我不想更改大小写).更具体地说,我想替换'data/和'之间的所有空格,因为数据库中的引号之间还有其他空格,例如:
I just want to change the spaces between the quotes (I don't want to change the capitalization). To be more specific I would like to replace any and all spaces between 'data/ and ' because there are other spaces between quotes in the DB, for example:
'data/ REPLACE ANY SPACE HERE '
我发现了:
\s(?!(?:[^']*'[^']*')*[^']*$)
,但在其他地方,引号之间也有空格,因此我想在开始时搜索 data/
,而不仅是单引号,而且我不知道该怎么做.我尝试了 \ s(?!(?:[^'data \/] *'[^'] *')* [^'] * $)
,但是它没有用,我是对正则表达式不够熟悉,无法做到这一点.
but there are other places where there are spaces between quotes so I'd like to search for data/
in the beging and not just a single quote but I can't figure out how. I tried \s(?!(?:[^'data\/]*'[^']*')*[^']*$)
but it didn't work and I am not familiar enough with regex to make it do so.
数据库中整行的示例是:
An example of a full line from the database is:
(712, 'GRTE-P', '', 'data/green tea powder.jpg', '2014-03-12 22:52:03'),
我不想在行尾的时间和数据戳中替换空格,而只是图像文件名.
I don't want to replace the spaces in the time and data stamp at the end of the line, just the image file names.
提前感谢您的帮助!
推荐答案
您必须使用基于 \ G
的模式来确保匹配是连续的.
You have to use a \G
based pattern to ensure that matches are contiguous.
搜索:(?:\ G(?!^)|'data/)[^'] * \ K []
替换: _
第一个匹配项使用交替的第二个分支,然后下一个匹配项是连续的,并使用第一个分支.
The first match uses the second branch of the alternation, then the next matches are contiguous and use the first branch.
这篇关于正则表达式查找单个qoutes之间的空间并替换为下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!