tags:

views:

47

answers:

4

Im looking for a ruby regex to match this

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

however - what 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.

+2  A: 

Try:

@variables\{[^}]*}

[^}] matches any character except }.

Bart Kiers
thanks a bunch!
No problem. (15 chars minimum)
Bart Kiers
A: 

How about this:

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

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

John Knoeller
A: 

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">
glenn jackman