You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-dev@jakarta.apache.org by prasanna shetty <pr...@attbi.com> on 2002/03/29 21:57:04 UTC
backreferences
i'm trying to change foo_28.xml to blah_28.xml.
here's how i'm trying to do this. note: both foo_28.xml and blah_28.xml are
user defined in a web based application. i'm hardcoding it in the example
below
RE r = new RE("foo_([0-9]{2}).xml");
String new = r.subst("foo_28.xml", "blah_\1.xml");
Doesn't work. i get blah_\1.xml
any suggestions would be appreciated.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: backreferences
Posted by Holger Stratmann <Ho...@cheerful.com>.
Hi prasanna (sorry, which is the first name?),
> RE r = new RE("foo_([0-9]{2}).xml");
> String new = r.subst("foo_28.xml", "blah_\1.xml");
>
> Doesn't work. i get blah_\1.xml
Well... the reason for this is obvious (sadly enough):
RegExp does NOT support replacing backreferences...
> any suggestions would be appreciated.
I faced the same problem a few weeks ago and since I wanted to stick with the
"lightweight" regexp, I implemented backrefs for myself. It's not yet
"completely complete" (mostly, escaping backslashes is still missing). I'm
planning to take another look at it soon, finish it and also submit the code...
(along with a few other fixes and extensions)
Right now, I implemented the functionality by subclassing rather than modifying
RE.java (assuming there might be updates, I didn't want to "merge" my changes
:-)
If you (or anybody else?) want to have the sources, just send me an e-mail...
If you prefer using "standard packages", I guess you could use ORO...
HTH,
Holger
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>