[英]Regex in Notepad++ for replacement
i've search for that info, but can't to figure out how to understand properly a regular expression. 我已经搜索了该信息,但无法弄清楚如何正确理解正则表达式。 I have a html file and there are multiple
<img>
tags. 我有一个html文件,并且有多个
<img>
标记。 Each of these tags have attribe src
with following data: /newsletter/images/light/b/NUMERICVALUE/IMAGENAME.jpg
这些标签中的每一个都具有带有以下数据的attribe
src
: /newsletter/images/light/b/NUMERICVALUE/IMAGENAME.jpg
Assuming that the NUMERICVALUE
and the IMAGENAME
are always different value in each src
attribute. 假设
NUMERICVALUE
和IMAGENAME
在每个src
属性中始终是不同的值。
What i need is to remove /NUMERICVALUE
from each url. 我需要从每个URL中删除
/NUMERICVALUE
。 How i suppose to do that ? 我应该怎么做?
Thanks for any suggestion. 感谢您的任何建议。
Here are a list of examples: 以下是示例列表:
/newsletter/images/light/b/617359405/lf-header.jpg
/newsletter/images/light/b/617359406/up-logo.jpg
/newsletter/images/light/b/617359407/logo-header.jpg
/newsletter/images/light/b/617359405/lf-header.jpg
/newsletter/images/light/b/617359406/up-logo.jpg
/newsletter/images/light/b/617359407/logo-header.jpg
Search: src=\\"\\/newsletter\\/images\\/light\\/b\\/[^\\/]*\\/([^\\"]*)\\"
搜索:
src=\\"\\/newsletter\\/images\\/light\\/b\\/[^\\/]*\\/([^\\"]*)\\"
Replace: src="/newsletter/images/light/b/\\1"
替换:
src="/newsletter/images/light/b/\\1"
Explanation: 说明:
\\/newsletter\\/images\\/light\\/b\\/[^\\/]*\\/([^\\"]*)
\\/newsletter\\/images\\/light\\/b\\/[^\\/]*\\/([^\\"]*)
[^\\/]*
[^\\/]*
([^\\"]*)
([^\\"]*)
(
and )
tells the regular expression engine to capture the content of it (
和)
告诉正则表达式引擎捕获其内容 \\1
forces the regular expression engine to insert capture 1
at this place \\1
,正则表达式引擎将捕获1
插入此位置 Edit : Updated to be used on all src=
attributes as mentioned in the comments. 编辑 :更新为可在注释中提到的所有
src=
属性上使用。
I guess NUMERICVALUE is an actual numeric value, so a simple solution: 我猜NUMERICVALUE是一个实际的数值,所以一个简单的解决方案:
Find what: /newsletter/images/light/b/\d+/([a-zA-Z0-9_]+).jpg
Replace with: /newsletter/images/light/b/\1.jpg
change contents of [a-zA-Z0-9_]
to what you need. 将
[a-zA-Z0-9_]
内容更改为所需的内容。
This barely programming-related but anyway: 这几乎与编程无关,但无论如何:
Find what: (<img src=.*/)\d+/
Replace with: \1
Input: 输入:
<img src="/newsletter/images/light/b/654/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/5752/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/78697345/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/7896789/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/45/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/8/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/4567837/IMAGENAME.jpg"/>
Output: 输出:
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
<img src="/newsletter/images/light/b/IMAGENAME.jpg"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.