简体   繁体   中英

Ruby regex match specific string with special conditions

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|$)

?:使群组不被捕获。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM