开发者

Regex: Finding specific word, excluding ones surrounded with a special char/tag

I want to find a specific word in a text, but not the ones that surrounded with a special char, or tag, etc.

For example:

This word should be find, but [this word] shouldn't.

Is it possible to do this with Regular Expression? Or I should thi开发者_StackOverflownk about writing a special parser?

Thanks.


Try the following

(^|[^\[])[Tt]his word($|[^$\]])

(^|[^\[]) -> line start or everything except an opening square bracket

[Tt]his word -> make the first letter case insensitive

($|[^\]]) -> line end or everything except an closing square bracket

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜