![](/img/trans.png)
[英]Regex to match anything (including the empty string) except a specific given string
[英]Regex to match anything, string, multiple,strings including newline non greedy in VIM
我想在其中替换小写的字符串:
SELECT lower1, lower2, lower3 FROM lower4, lower5 WHERE
我使用vim replace将此正则表达式替换为大写:
:%s/select\\_.*\\from\\_.*\\where/\\U&/gic
当存在其他选择查询时,正则表达式select\\_.*\\from\\_.*\\where
不好:
例如,它选择此查询中的所有内容并影响不能大写的字符串
SELECT lower1, lower2, lower3 FROM lower4, lower5 WHERE lower1=cannot_be_uppercased
UNION all
SELECT lower1, lower2, lower3 FROM lower6, lower7 WHERE lower1=cannot_be_uppercased
Vim里正则表达式非贪婪模式。 代替使用*
,使用\\{-}
。
我想,正则表达式select\\_.\\{-}from\\_.\\{-}where
。
这是一些文档。
:h non-greedy
*non-greedy*
If a "-" appears immediately after the "{", then a shortest match
first algorithm is used (see example below). In particular, "\{-}" is
the same as "*" but uses the shortest match first algorithm. BUT: A
match that starts earlier is preferred over a shorter match: "a\{-}b"
matches "aaab" in "xaaab".
Example matches ~
ab\{2,3}c "abbc" or "abbbc"
a\{5} "aaaaa"
ab\{2,}c "abbc", "abbbc", "abbbbc", etc.
ab\{,3}c "ac", "abc", "abbc" or "abbbc"
a[bc]\{3}d "abbbd", "abbcd", "acbcd", "acccd", etc.
a\(bc\)\{1,2}d "abcd" or "abcbcd"
a[bc]\{-}[cd] "abc" in "abcd"
a[bc]*[cd] "abcd" in "abcd"
The } may optionally be preceded with a backslash: \{n,m\}.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.