Notepad++使用正则表达式替换字符串(索引=内容)

Notepad++使用正则表达式替换字符串(索引=内容),第1张

Notepad++使用正则表达式替换字符串(索引=内容)

待替换的文本:


复制代码代码如下:
<link rel="stylesheet" title="Default" href="styles/default.css">
<link rel="alternate stylesheet" title="Dark" href="styles/dark.css">
<link rel="alternate stylesheet" title="FAR" href="styles/far.css">
<link rel="alternate stylesheet" title="IDEA" href="styles/idea.css">
<link rel="alternate stylesheet" title="Sunburst" href="styles/sunburst.css">
<link rel="alternate stylesheet" title="Zenburn" href="styles/zenburn.css">
<link rel="alternate stylesheet" title="Visual Studio" href="styles/vs.css">
<link rel="alternate stylesheet" title="Ascetic" href="styles/ascetic.css">
<link rel="alternate stylesheet" title="Magula" href="styles/magula.css">
<link rel="alternate stylesheet" title="GitHub" href="styles/github.css">
<link rel="alternate stylesheet" title="Google Code" href="styles/googlecode.css">
<link rel="alternate stylesheet" title="Brown Paper" href="styles/brown_paper.css">
<link rel="alternate stylesheet" title="School Book" href="styles/school_book.css">
<link rel="alternate stylesheet" title="IR Black" href="styles/ir_black.css">
<link rel="alternate stylesheet" title="Solarized - Dark" href="styles/solarized_dark.css">
<link rel="alternate stylesheet" title="Solarized - Light" href="styles/solarized_light.css">
<link rel="alternate stylesheet" title="Arta" href="styles/arta.css">
<link rel="alternate stylesheet" title="Monokai" href="styles/monokai.css">
<link rel="alternate stylesheet" title="XCode" href="styles/xcode.css">
<link rel="alternate stylesheet" title="Pojoaque" href="styles/pojoaque.css">
<link rel="alternate stylesheet" title="Rainbow" href="styles/rainbow.css">
<link rel="alternate stylesheet" title="Tomorrow" href="styles/tomorrow.css">
<link rel="alternate stylesheet" title="Tomorrow Night" href="styles/tomorrow-night.css">
<link rel="alternate stylesheet" title="Tomorrow Night Bright" href="styles/tomorrow-night-bright.css">
<link rel="alternate stylesheet" title="Tomorrow Night Blue" href="styles/tomorrow-night-blue.css">
<link rel="alternate stylesheet" title="Tomorrow Night Eighties" href="styles/tomorrow-night-eighties.css">

想要的格式如下:

索引 = 内容

其中,索引为 href属性中的css文件名(不含扩展名),内容为 title属性。如果普通替换,可以得到内容 = 索引 格式的结果,可是剩下的就得手动替换了。

用正则表达式,一步就可以搞定,正则式为:


复制代码代码如下:
.+=\".+\".+=\"(.+)\".+=\"\w+\/(.+)[.].+

替换规则:

复制代码代码如下:
\2 = \1

替换后结果:


复制代码代码如下:
default = Default
dark = Dark
far = FAR
idea = IDEA
sunburst = Sunburst
zenburn = Zenburn
vs = Visual Studio
ascetic = Ascetic
magula = Magula
github = GitHub
googlecode = Google Code
brown_paper = Brown Paper
school_book = School Book
ir_black = IR Black
solarized_dark = Solarized - Dark
solarized_light = Solarized - Light
arta = Arta
monokai = Monokai
xcode = XCode
pojoaque = Pojoaque
rainbow = Rainbow
tomorrow = Tomorrow
tomorrow-night = Tomorrow Night
tomorrow-night-bright = Tomorrow Night Bright
tomorrow-night-blue = Tomorrow Night Blue
tomorrow-night-eighties = Tomorrow Night Eighties

来自:annhe.net

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/1332499.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存