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 Schamil Wackenhut <sw...@wacke.org> on 2003/06/05 10:41:01 UTC

Re: Replacing with backrefs does not work, can anybody explain why?

* Val Starovoitov meinte:

> new RE( "(..)ple").subst ( "Apple is tasty", "\\1ricot");
> Returns:             "\1ricot is tasty"
> My expectation:   "Apricot is tasty"

Try \1ricot. The problem is you escape the second backslash
instead of 1.
-- 
/earth: file system full.


---------------------------------------------------------------------
To unsubscribe, e-mail: regexp-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: regexp-user-help@jakarta.apache.org


Re: Replacing with backrefs does not work, can anybody explain why?

Posted by Val Starovoitov <va...@picknowl.com.au>.
Hi, Schamil,
replacement of "\\1" to "\1" does not work because:
1) I have tried that and it produced a replace string like: "?ricot" with symbol with ASCII code 1, as it supposed to be.
2) If RE understands "\\1" in the 2nd example in search string, then it was done OK and should work in the 1st example. 

These are examples from my 1st letter:
Example1 
(in replace - does not work):
new RE( "(..)ple").subst ( "Apple is tasty", "\\1ricot");
Returns:             "\1ricot is tasty"
My expectation:   "Apricot is tasty"

Example2 
(in search - does work):
new RE( "(.)=\\1").subst ( "0=0 is correct", "1=1");
Returns:             "1=1 is correct"

Cheers,
Val.

----- Original Message ----- 
From: "Schamil Wackenhut" <sw...@wacke.org>
To: "Regexp Users List" <re...@jakarta.apache.org>; "Val Starovoitov" <va...@picknowl.com.au>
Sent: Thursday, June 05, 2003 18:11
Subject: Re: Replacing with backrefs does not work, can anybody explain why?


> * Val Starovoitov meinte:
> 
> > new RE( "(..)ple").subst ( "Apple is tasty", "\\1ricot");
> > Returns:             "\1ricot is tasty"
> > My expectation:   "Apricot is tasty"
> 
> Try \1ricot. The problem is you escape the second backslash
> instead of 1.
> -- 
> /earth: file system full.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: regexp-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: regexp-user-help@jakarta.apache.org
> 
>