
假設我有這樣的文字:
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/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
但任何類似的嘗試都會失敗。
答案1
您可以使用:
^.*?[Mm]odels.*?$
解釋:
^
- 匹配行的開頭.*?
- 任何內容,非貪婪,在您要尋找的單字之後和之前[Mm]odels
- 不區分大小寫models
。將其包裹在\b
s 中以確保egsomeothermodels
不匹配。$
- 行結束
然後替換為:
\L$0
在 Notepad++/Sublime Text 3 使用的 Boost 正規表示式引擎中,這意味著\L
將小寫其後的任何內容並且$0
完全匹配,因此整個匹配行。