Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想搜索每一次出现main.并用空字符串替换它。该表达式\b^main\.在我的测试中有效,但在我的文件中没有发现任何出现。我是否需要修改表达式才能使其工作?
main.
\b^main\.
你应该使用正则表达式模式
\bmain[.]
或者
\bmain\.
特殊字符^表示行或字符串的开头,它不应该是您的正则表达式模式的一部分。特殊字符\b代表一个单词边界,这就是你需要在main字符串前面的所有内容。因为点.代表正则表达式中的任何字符,您需要对其进行转义或放入方括号[]中,因此它仅代表真正的点/句点字符。
^
\b
main
.
[]