Javascript正则表达式匹配冒号和以点结尾的句子之间的文本
假设我有这样的文本:
这是标题:\ 标题始终带有冒号
这是一个常规句子。
句子总是以句号结尾。
一句话就可以
跨越多行。
一个句子可以包含 123 等数字。
该短语还可以包含“用双引号引起来的文本” 或“用单引号括起来的文本”。
句子中可能出现的其他符号有
逗号,
分号 ;
美元符号 $
括号 ( )
加号 + 减号 - 和方括号[ ]。这是一个孤立的短语,正则表达式不应匹配。
如何在 javascript 中创建正则表达式来匹配第一个冒号*和 brackets[ ]
之后的最后一个句号之间的文本? (假设没有其他冒号,如果有的话,它们将用双引号括起来)
我尝试使用 :.*
但它会匹配所有行。
Suppose I have a text like this:
This is the title: \ titles always have a colon
This is a regular sentence.
A sentence always ends with a period.
A sentence can
span multiple lines.
A sentence can contain numbers like 123.
The phrase can also contain "text enclosed in double quotes"
or 'text enclosed in single quotes'.
Other symbols that may appear in sentences are
the comma ,
the semicolon ;
the dollar sign $
parentheses ( )
the plus sign +
the minus sign -
and the square brackets[ ].This is an isolated phrase that the regular expression should not match.
How could I create a regex in javascript to match the text between the first colon* and the last full stop after brackets[ ]
? (assuming there will be no other colon, if there are any, they will be enclosed in double quotes)
I've tried using :.*
but it maches all lines.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 s 标志,以下正则表达式捕获冒号之后直到双换行符的所有内容。
此处在 regex101 上进行测试
Using the s flag, the following regex captures everything after the colon till the double linebreak.
Test on regex101 here