ruby recursive regex
- by Reed Debaets
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