开发者

Ruby regex match specific string with special conditions

开发者 https://www.devze.com 2022-12-25 23:10 出处:网络
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:

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?


(?:\s|^)(Func)(?:\s|$)

?: makes a group non-capturing.

0

精彩评论

暂无评论...
验证码 换一张
取 消