in reply to A (non) reg-ex question

You can't. Yes you can. You got the implemented answer. Just a blurb on why you can't, but perl breaks the rule.

The long, "you can't," answer: A regexp, an achedemic regexp, won't work. I point that out since your example is a perl regular expression. I suggest looking up the pumping lemma and the basic tenants of a regular language. In short, what you need is something that requires stack memory. A real regular expression only needs memory for the input, the expression itself, and a pointer to say where weare at in the regexp. If the number of 0's and 1's have some sort of arithmetic relation, more likely than not, you can't. There are exceptions.

The long, "you can," answer: perl's regexp's are an extension of the regular expressions used for regular languages. The fact you have the /e flag totally completely blows it out of the water since oyu can freely allocate variables. Perl's regex's are a wonderful thing. Just stating the fact you can do context sensitive stuff in it.

Replies are listed 'Best First'.
Re^2: A (non) reg-ex question
by bart (Canon) on Mar 21, 2006 at 11:03 UTC
    The /e flag does not work on a regex. Instead, it's a flag that says the right hand side of a s///, which is a string, needs to be treated as code. The regex is the left hand side in s/// (or the whole thing in //).

    Surely you must have been thinking of (?{CODE}) and friends? (See perlre)

      Yeah, thanks. Whoops.