将字符串捕获到字符但不包括字符

时间:2012-12-03 16:22:26

标签: regex

使用字符串http://stackoverflow.com/questions/ask?hello=world,您可以使用/^.+\?/来捕获http://stackoverflow.com/questions/ask?。我怎样才能捕获http://stackoverflow.com/questions/ask

3 个答案:

答案 0 :(得分:1)

将正则表达式中与所需字符串匹配的部分括在括号中,并使用组来检索它。

 /(^.+)\?/

第1组将包含除尾随?之外的整个匹配字符串。

答案 1 :(得分:1)

使用此regexrpession /^.+(?=\?)/

答案 2 :(得分:1)

您可以使用^[^?]+

这将捕获,直到找到问号,但问号不会出现在结果中。

Check it out

相关问题