开发者

ruby regex to match @variables{whatever, text, numbers, hex - not important}

Im looking for a ruby regex to match this

@variables{ color1 | #FFFFFF | links; color2 | #c1dfee | frame; }

however - w开发者_开发百科hat is inside the braces is not important. I just want to capture that @variables{} with its content. So I guess Im looking for something like /@variables{MATCH-ANYTHING}/m

Thanks.


Try:

@variables\{[^}]*}

[^}] matches any character except }.


how about /@variables\{[^}]*\}/


How about this:

/@variables\{(.+)\}/.match("@variables{ color1 | #FFFFFF | links; color2 | #c1dfee | frame; }")[1]


Alternatively: /@variables\{.*?}/ to match anything between braces non-greedily

s = "foo{bar} @variables{blah blah} asdf{zxbc}"
s.match(/@variables\{(.*?)}/)
# => #<MatchData "@variables{blah blah}" 1:"blah blah">
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜