【发布时间】:2018-07-28 13:59:28
【问题描述】:
我有一个这样的字符串:
this text (an another text) "and a text" and again a text
我想要的是只匹配第一个text。其他两个 text 单词要么在括号内,要么在引号中。
this text (an another text) "and a text" and again a text
^ this is I do want to capture. and this -> ^
如何在单个正则表达式匹配中做到这一点?我无法在一次比赛中为这两种情况找到任何解决方案。
文本可以是任意顺序。
【问题讨论】:
-
你的意思是(?:(.*)|".*")|(text) 吗?
-
它们可以按任何顺序排列吗?
-
@Eric,是的,它们可以按任何顺序排列。
-
@UnbearableLightness 让我试试。 .. 更新:无论什么,它都会选择所有文本。尝试使用正则表达式应用程序。
标签: javascript regex