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">
精彩评论