Ruby 正则表达式匹配具有特殊条件的特定字符串
我目前正在尝试借助正则表达式将文档解析为标记。
目前我正在尝试匹配文档中的关键字。例如我有以下文档:
Func test()
Return blablaFuncblabla
EndFunc
需要匹配的关键字是Func、Return和EndFunc。
我想出了以下正则表达式: (\s|^)(Func)(\s|$) 来匹配 Func 关键字,但它并不完全按照我想要的方式工作,空格也匹配!
如何在不捕获空格的情况下匹配它?
I'm currently trying to parse a document into tokens with the help of regex.
Currently I'm trying to match the keywords in the document. For example I have the following document:
Func test()
Return blablaFuncblabla
EndFunc
The keywords that needs to be matched is Func, Return and EndFunc.
I've comed up with the following regex: (\s|^)(Func)(\s|$) to match the Func keyword, but it doesn't work exactly like I want, the whitespaces are matched as well!
How can I match it without capturing the whitespaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
?:
使组不被捕获。?:
makes a group non-capturing.