开发者

How do I make a regex with a lookbehind assertion that still works at the start of a string

I need to emulate the behavior of \b开发者_高级运维 at the start of a string, where I'm adding additional characters to the set that count as a word boundary. Right now I'm using something like:

"(?<=\\W|\\p{InCJKUnifiedIdeographs})foo"

This works as I would like, unless I'm at the start of the string being matched: in which case the assertion fails and I don't get a hit. What I want is the equivalent of match if I'm at the start of the string or foo is preceded by a non-word character or an ideograph. But I can't get the right incantation to support that.

Any thoughts? Or is this impossible?

Thanks in advance.


"(?<=^|\\W|\\p{InCJKUnifiedIdeographs})foo"

Just add the start-of-string anchor to the lookbehind conditions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜