Bug 22928 - subst() with REPLACE_BACKREFERENCES cuts first 2 characters
Summary: subst() with REPLACE_BACKREFERENCES cuts first 2 characters
Alias: None
Product: Regexp
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal with 1 vote (vote)
Target Milestone: ---
Assignee: Jakarta Notifications Mailing List
: 22966 36106 (view as bug list)
Depends on:
Reported: 2003-09-04 09:25 UTC by Sascha Spiekermann
Modified: 2005-08-10 20:54 UTC (History)
2 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Sascha Spiekermann 2003-09-04 09:25:50 UTC
Just tried the new subst()-Method with the pattern "http://[\.\w\-\?/~_@&=%]+", 
input "visit us: http://www.apache.org!" and substitution "1234<a 
href="$0">$0</a>". The call of subst
(input,substitute,RE.REPLACE_BACKREFERENCES) produces "visit us: 34<a 
href="http://www.apache.org">http://www.apache.org</a>!", the first two numbers 
are cut away.
Another Try: "variable=value" against "(.*?)=(.*)" and "$1_test=$2" produces 

String index out of range: -2
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
	at java.lang.String.substring(String.java:1480)
	at org.apache.regexp.RE.subst(Unknown Source)

Same call, just "12$1_test=$2" as the substitution produces the right 
result: "variable_test=value"

Another Question: Why does "subst()" use $x as backreference, otherwise "\x" is 

-Sascha Spiekermann
Comment 1 Vadim Gritsenko 2003-09-06 01:49:07 UTC
Got a patch from Tobias, applied to CVS. Added test to the retest.java.
Please check.
Comment 2 Tobias Schaefer 2003-09-07 07:28:47 UTC
I cannot remember exactly why I used $x. 
pro: "$" does not need to be escaped in java source code 
con: "\" is more commonly used. 
Bug is closed. 
Comment 3 Vadim Gritsenko 2003-09-07 15:02:51 UTC
*** Bug 22966 has been marked as a duplicate of this bug. ***
Comment 4 Vadim Gritsenko 2005-08-11 04:54:55 UTC
*** Bug 36106 has been marked as a duplicate of this bug. ***