假设我有这样的文字:
models/players/clonespac/CloneTorsoLieutenant
{
q3map_nolightmap
q3map_onlyvertexlighting
{
map models/players/clonespac/CloneTorsoLieutenant
blendFunc GL_ONE GL_ZERO
rgbGen lightingDiffuse
}
{
map gfx/effects/clone
blendFunc GL_DST_COLOR GL_SRC_COLOR
tcGen environment
blendFunc GL_SRC_ALPHA GL_ONE
detail
alphaGen lightingSpecular
}
}
我想将所有字母转换为小写,但前提是该行包含单词“models”。
结果是这样的:
models/players/clonespac/clonetorsolieutenant
{
q3map_nolightmap
q3map_onlyvertexlighting
{
map models/players/clonespac/clonetorsolieutenant
blendFunc GL_ONE GL_ZERO
rgbGen lightingDiffuse
}
{
map gfx/effects/clone
blendFunc GL_DST_COLOR GL_SRC_COLOR
tcGen environment
blendFunc GL_SRC_ALPHA GL_ONE
detail
alphaGen lightingSpecular
}
}
我知道我可以这样做:
(\w)
->\L$1
但它替换了每个字符。
我尝试这样做:
models (\w)
->models \L$1
但任何类似的尝试都会失败。
您可以使用:
解释:
^
- 匹配行的开头.*?
- 任何东西,非贪婪,在您要查找的单词之后和之前[Mm]odels
- 不区分大小写models
。将其包裹在\b
s 中以确保egsomeothermodels
不匹配。$
- 行结束然后替换为:
在 Notepad++/Sublime Text 3 使用的 Boost 正则表达式引擎中,这意味着
\L
将小写其后的任何内容并且$0
完全匹配,因此整个匹配行。