简体   繁体   English

正则表达式:句子开头的匹配词

[英]Regular Expression: match word at start of sentence

I am wanting to match all occurrences of a certain word (in this case "Jill") that start a sentence in the middle of a paragraph. 我想匹配某个单词(在本例中为“ Jill”)的所有出现,该单词在段落的中间开始一个句子。

"Hello sample string. Jill is great." “你好,采样字符串。吉尔很棒。”

Now the expression [.:?!]\\sJill\\b will match this but matches at the position of the full stop. 现在表达式[.:?!]\\sJill\\b[.:?!]\\sJill\\b匹配,但在句号位置匹配。 Is it possible to match at the start of the 'J' in "Jill"? 是否可以在“吉尔”中的“ J”开头匹配?

I'm using the c# flavour of regex. 我正在使用正则表达式的C#风格。

Try this. 尝试这个。 I haven't tested it yet. 我还没有测试。 (?<=[.:?!]\\s)Jill\\b

您是否考虑过使用分组来捕获Jill?

[.:?!]\s(Jill)\b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM