[英]javascript regex match the string excluding ending pattern
Can anyone please help me with this: 谁能帮我这个忙:
I'm stuck with JS regular expression. 我坚持使用JS正则表达式。
I have a string like: 我有一个像这样的字符串:
idont test 33lkjrhguegh8438934hihfer TEST2 oidchschds idont 测试 33lkjrhguegh8438934hihfer TEST2 oidchschds
I want to match everything between test
and TEST2
excluding TEST2
. 我想匹配test
和TEST2
之间的所有内容(不包括TEST2
。
So the expected output would be: 因此,预期输出为:
test 33lkjrhguegh8438934hihfer 测试 33lkjrhguegh8438934hihfer
I've tried the following with no success :( : 我尝试了以下没有成功的方法:(:
(test)(.*)(?:(?!(TEST2)))
(test)(.*)(?:(TEST2))
(test)(.*)(?:(?!TEST2))
(test)(.*)(?:TEST2)
(test)(.*)(TEST2) //almost works but selects TEST2 also
You can use: 您可以使用:
/(test.+?)TEST2/
and use captured group #1 or using a positive lookahead : 并使用捕获的#1组或使用正向前瞻 :
/test.+?(?=TEST2)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.