ruby recursive regex
Posted
by Reed Debaets
on Stack Overflow
See other posts from Stack Overflow
or by Reed Debaets
Published on 2010-04-15T18:40:47Z
Indexed on
2010/04/15
18:43 UTC
Read the original article
Hit count: 407
So why is this not working? I'm creating a regex that will match a formula (which is then part of a larger standard description). But I'm stuck here, as it doesn't appear to want to match embedded formulas within a formula.
stat = /(Stat3|Stat2|Stat1)/
number_sym = /[0-9]*/
formula_sym = /((target's )?#{stat}|#{number_sym}|N#{number_sym})\%?/
math_sym = /(\+|\-|\*|\/|\%)/
formula = /^\((#{formula}|#{formula_sym}) (#{math_sym} (#{formula}|#{formula_sym}))?\)$/
p "(target's Stat2 * N1%)".match(formula).to_s #matches
p "((target's Stat2 * N1%) + 3)".match(formula).to_s #no match
p "(Stat1 + ((target's Stat2 * N1%) + 3))".match(formula).to_s #no match
© Stack Overflow or respective owner