开发者

Ruby regex for matching simpliest Ruby's regexes

I want to match regexes (at least the basic ones, not all their possible kinds... for now...) in a text of Ruby script.

It's something like a... 开发者_运维问答\/\^? oh my god... \$?\/[eimnosux]*

Maybe I need recursive regex here.


As I commented above, you'll need to parse Ruby to differentiate division slashes and regex delimiters. But for the simplest, SIMPLEST case without worrying about this, how about:

regex_match = %r{/(?:[^/\\]|\\.)+/[mgixo]*}

That is "A forward slash, followed by one or more things that either aren't a forward slash or a backslash, or are a backslash followed by something else, finally followed by a slash, and possibly some regex flags."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜