On Fri, 29 Sep 2000 00:29:31 +0100, Hugo wrote:

>:I originally had thought of providing a separate, dedicated regex 
>:modifier, just for the match prefix, but I don't think too many people 
>:need this that desperately. You can easily build a working application 
>:with just the '/z' modifier. If you can't, you're in over your head, 
>:anyway.  ;-)
>
>I don't understand this paragraph.

I'll have to rework this into plain English. Look, I think it would be
cool if there were a special modifier, let's call it '/p', that allows a
regex to succeed not only if the whole regex matches, but also if it
only matches a prexi, so:

        $pat = '\d+\.?\d*(?:E[+-]?\d+)?';
        for('1234E', '1234EE') {
            if(/^$pat$/p) {
                 print "Found a prefix in '$_'!\n";
            } else {
                 print "'$_' does not look acceptable\n";
            }
        }

That this would say "yes" to "1234E", but no to "1234EE". "1234E" can be
a prefix for "1234E-2", for example, while "1234EE" cannot possibly made
to match, whatever you append.

Now, basically, the regex engine HAS the built-in possibility to return
this: adding such a modifier wouldn't be too hard a work, I would think.
All you need to do is check lookahead: if it ever bumps into the end of
the string, this thing is a prefix.

But, as I wrote in the RFC, this detecting a prefix is just a part of a
grander picture: detecting when we have "sufficient data" to do a
reliable match, when processing data in chunks. We also need to know how
much of the old data we need to keep, in case we need to append more
data. I admit, my current attempt is not too successful with regards to
//gc. I tried to make the impact on the current language minimal, while
providing this extra power. Perhaps I need a more elaborate effect.
Setting a new special variable would be the easy way out, but I'm not in
favour of it.

p.s. I often wondered why pos() is not just a special variable. That
would make more sense, I think, from a user POV, than making it a
special function.

-- 
        Bart.

Reply via email to