dblack / wobblini.net writes:

> On Sat, 15 Jul 2006, Daniel Martin wrote:
>> Perl allows bunches of special constructs in regular expressions that
>> sane languages, which like to keep the matching of regular expressions
>> away from being able to jump back into the host language.  (Note that
>> perl combines this feature with extra language-level security support,
>> since most programmers would assume that a user-supplied regexp
>> couldn't execute arbitrary code)
>
> Ruby does let you jump back, though, with #{...}.  But it looks like
> Perl does an extra level of compilation.  (Unless I've got that
> backwards.)

Ruby lets you do string interpolation with an easy syntax, and lets
you use that syntax even when writing a string that is being compiled
into a regular expression because it's surrounded by //.  Perl has
that, too.  This however is something different - the execution of
code in the host language at regular expression long after the
expression has been compiled, in the middle of doing a match.

As I said, most languages don't allow this.  The usual pattern is:
1 make string in language-specific way
2 hand string to regexp engine and get back some compiled structure
3 store handle to compiled structure in host language
4 get string to match
5 hand string and compiled structure to regexp engine
6 regexp engine walks the string and compiled structure to determine
  if there's a match.

Now, for speed, step 6 is generally done in C.  Sometimes, so is step
2.  (I haven't looked at the ruby code, but python does steps 1-5 in
python, and only 6 in C.  Java's regexp engine of course does all
those steps in java)

Perl, however, lets you interrupt step 6 and evaluate some perl code
in the midst of the C-based matching code.