gnu-regexp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Regexp] How to use literal $ amounts in replace string for RE.subst


From: Shashank Bapat
Subject: Re: [Regexp] How to use literal $ amounts in replace string for RE.substituteA ll(String,String)
Date: Thu, 16 May 2002 08:14:46 -0700 (PDT)

> 2) Out of curiosity, why does gnu.regexp use
> $1,$2,$3,etc when Perl uses \1,\2,\3 for sub
> expressions?

Well, I think perl allows for $<digit> as well as
\<digit> but these two behave little differntly. The
difference is that using $ allows you to refer to
subexpr outside the pattern. In case of perl $<digit>
is valid in the enclosing block (ie {...} ). I think
as far as using this package in java goes above
difference does not count at all. 

But I guess if \<digit> is not working then it should
work as well. It will be a step closer to correct and
complete copy of perl syntax.

About the first question. If you are saying that you
already traced through the code and theres no way to
escape then thats a bug and someone will soon address
it. 

Till then if its a plane non RE string match - which
is the case with your example - use String.indexOf() 
and StringBuffer.replace() ... If its RE then you can
get match index using RE and then use
StringBuffer.replace() ... if your replace is also
nonRE but contains $, use something else for $ and
then replace it by $ using String's $ ... Ugly hack.
-Shashank

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]