我正在尝试执行替换。考虑以下字符串:
Please replace something in this sentence.
and replace <b>something </b> in this sentence.
But not here http://www.mysite.com/something/mypage.html
Or here \\myserver\something\myshare\
我想替换something
为somethingelse
,但是something
可以出现在我的源代码中的 URL 或 UNC 中,我不想替换它。我还有一些有趣的 HTML 正在进行。
这是我正在使用的模式:
\b[^/\\]Something[^/\\]\b
哪个有效,但是我也得到了第一个something
后面的空间。如果我替换something
为somethingelse
我得到的结果:
Please replacesomethingelsein this sentence.
and replace <b>somethingelse </b> in this sentence.
But not here http://www.mysite.com/something/mypage.html
Or here \\myserver\something\myshare\
第二个实例有效,第一个带有空格的实例无效。
如何忽略周围是否存在空格something
?谢谢你。