开发者

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

开发者 https://www.devze.com 2022-12-19 07:27 出处:网络
Im looking for a ruby regex to match this @variables{ color1 | #FFFFFF | links; color2 | #c1dfee | frame;

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

精彩评论

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