You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-user@jakarta.apache.org by mf...@bci.cl on 2002/10/17 22:04:51 UTC

Better name for .getParen(0)

Hi. (I'm the new guy in the list, just discovered regexp, blah blah blah)

I've been tinkering around with Regexp, and there's one thing that calls my
attention: in order to obtain whatever the last regexp match was, one must
use r.getParen(0) (with r being a RE class, etc.). I find this... not
intuitive/clear enough. I'd rather have a method called getMatched() that
would do the same thing.

So, I added it to the RE class. It's actually extremely simple:

    public String getMatched()
    {
        return getParen(0);
    }

There. It's not much, but I think it's much clearer to read code that goes:

if (r.match(address)) { System.out.println("We got: "+r.getMatched()); }

than

if (r.match(address)) { System.out.println("We got: "+r.getParen(0)); }

, for example.


I'll probably post more nitpicks as I keep tinkering.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>