在正则表达式中遗漏了什么?
我正在尝试使用这个正则表达式
art..*[A-Z].*s
在此处提取粗体文本
一些文字 bla艺术。100 个重要文本其他文本 bla
基本上,我想提取遵循此模式的所有文本:
*art.* *number* *whatever* *first word that starts in uppercase*
但它没有按预期工作。有什么建议吗?
回答
使用您显示的样本,请尝试以下操作。
bart..*?d+.*?[A-Z]w*
上述正则表达式的在线演示
说明:为以上添加详细说明。
b ##mentioning word boundary here.
art. ##Looking for word art with a literal dot here.
.*?d+ ##Using non-greedy approach for matching 1 or more digits.
.*?[A-Z]w* ##Using non-greedy approach to match 1 capital letter followed by word characters.