in reply to Possessive Quantifiers

Are you suggesting it is somehow better in Java because the syntax is shorter? Or, do you know something about the way that this is implemented in Java that makes it somehow better than the implementation in perl?

If it is the former, I'd argue that shorter syntax doesn't mean better, especially for such an infrequently used construct. Besides, if shorter syntax does mean better then Perl beats Java hands down overall. (Ever seen any Java golf? Me neither...)

If it is the latter, I'm interested in knowing what you do.

To answer your questions in order:
1. I don't know.
2. I don't think I've ever used it.
3. There is no cure. Soon you'll be making up regexes to match strings of cars on the freeway and other such nonsense.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Possessive Quantifiers
by Ferret (Scribe) on Aug 17, 2002 at 08:46 UTC

    I wish I knew something (significant) about the Perl or Java implementations. In fact, quite the opposite is true - I've done no more than read the quotes in the Perl headers, yet.:-P

    That's part of the reason I submitted this question. I'm quite aware that Perl beats Java hands down - the book has enough examples to nail that down even if I didn't already believe it from previous experience. I'm also aware that shorter isn't necessarily better.

    If there's some particular insight as to why it would be worse in this particular case, I'd be delighted to be enlightened. As it is, in my ignorance, I like the + possessive because I think it looks more readable than the (?>) alternative, and is likely a better mnemonic, since I have to keep looking at the man page to remember which odd character goes into (?>) .

    Java golf. That'd be a laugh. 'Look, I done it in 15!' 'Characters?' 'No, classes!' Thbbppt.

    note:Thanks to whoever edits the above link to regex.info for fixing my stupidity.

      If there's some particular insight as to why it would be worse in this particular case, I'd be delighted to be enlightened. As it is, in my ignorance, I like the + possessive because I think it looks more readable than the (?>) alternative, and is likely a better mnemonic, since I have to keep looking at the man page to remember which odd character goes into (?>) .

      I don't know enough about the Java half of this question to be strongly opinionated but I can offer some thoughts.

      The construct is mostly good for optimizing the failure case of a specific subset of patterns. Consequently, it is infrequently used in Perl and presumably, that's the case in Java as well. The symbol "+", however, is frequently used for a very common case. Overloading its meaning could be confusing.1 It might be easily missed or look like a typo, particularly to someone unfamiliar with it.

      The (?>) construct allows grouping that Java's doesn't seem to handle. I'm guessing2 that (?>a*b*) is equivalent to Java's a*+b*+. If so, and (?>a+b?c{3,7}d*e+) looks like a++b?+c{3,7}+d*+e++ in Java, then Java's representation starts to get long and messy. What about (?>a*(b|c)d*)? Can that be expressed in Java at all? Or is Java restricted to modifying quantifiers?

    1. It might be a real + for obfuscation though. :-)
    2. I'm not sure of this. Someone please correct me if I'm wrong.
    -sauoq
    "My two cents aren't worth a dime.";
    
        I'm guessing that (?>a*b*) is equivalent to Java's a*+b*+.

        The equivalent to Java's a*+b*+ would be (?>a*)(?>b*). In this case that wouldn't make a difference of course, but it would in situations like this one:

        $_ = "aaab"; print "/(?>[ab]+)(?>b+)/ matches $_\n" if /(?>[ab]+)(?>b+)/; print "/(?>[ab]+b+)/ matches $_\n" if /(?>[ab]+b+)/;
        What about (?>a*(b|c)d*)? Can that be expressed in Java at all?

        How about (a*(b|c)d*){1}+? (Yeah, it's ugly...)

        — Arien

Re: Re: Possessive Quantifiers
by Mr. Muskrat (Canon) on Aug 18, 2002 at 05:05 UTC

    sauoq said "3. There is no cure. Soon you'll be making up regexes to match strings of cars on the freeway and other such nonsense."

    Don't forget dreaming in regexes... (I always seem to wake up with a headache after those dreams.)