我正在尝试使用这个正则表达式
art\..*[A-Z].*\s
Run Code Online (Sandbox Code Playgroud)
在此处提取粗体文本
一些文字 bla艺术。100 个重要文本其他文本 bla
基本上,我想提取遵循此模式的所有文本:
*art.* *number* *whatever* *first word that starts in uppercase*
Run Code Online (Sandbox Code Playgroud)
但它没有按预期工作。有什么建议吗?
使用您显示的样本,请尝试以下操作。
\bart\..*?\d+.*?[A-Z]\w*
Run Code Online (Sandbox Code Playgroud)
说明:为以上添加详细说明。
\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.
Run Code Online (Sandbox Code Playgroud)