in reply to Abbreviation regex?

An alternative:
/^a($|b($|b($|r($|e($|v($|i($|a($|t($|i($|o($|n$)))))))))))/

In both yours and mine, (?:...) would be faster than (...). I left it as is for the sake of simplicity.

Of course, the simpliest solution would be substr($word, 0, length($str)) eq $str, but it's non-regexp.

Replies are listed 'Best First'.
Re^2: Abbreviation regex?
by Tanktalus (Canon) on Jan 16, 2006 at 17:37 UTC

    That's just screaming for factorisation. ;-)

    /^a(|b(|b(|r(|e(|v(|i(|a(|t(|i(|o(|n)))))))))))$/
    Or, to possibly make the abbreviation stand out a bit more at the expense of some readability:
    /^a(b(b(r(e(v(i(a(t(i(o(n|)|)|)|)|)|)|)|)|)|)|)$/

    (The non-toy solution probably involves Text::Abbrev.)