Notepad++使用正则表达式替换字符串

这些天做discuz插件,体验到了正则表达式的强大,恰好在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

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注