Summary: | In MATCH_MULTILINE-mode $ does not match end of line | ||
---|---|---|---|
Product: | Regexp | Reporter: | Hendrik Brummermann <nhb_web> |
Component: | Other | Assignee: | Jakarta Notifications Mailing List <notifications> |
Status: | CLOSED FIXED | ||
Severity: | normal | CC: | mvtm |
Priority: | P3 | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Hardware: | Other | ||
OS: | other | ||
Bug Depends on: | 4137 | ||
Bug Blocks: |
Description
Hendrik Brummermann
2004-01-08 12:55:13 UTC
I think that match() doesn't work due to bug #4137. I've verified that the problem is gone when suggested fix for 4137 applied. But after this I get exception in subst() Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind ex out of range: -1 at java.lang.String.substring(String.java:1480) at org.apache.regexp.RE.subst(RE.java:1784) at Bug25985.main(Bug25985.java:9) It occured because we specify RE.REPLACE_BACKREFERENCES flag for subst(), but substitution parameter dosn't contain any such references. Thus we try to execute the following line: // Append everything after the last $ sign ret.append(substitution.substring(lLastPosition+2,lLength)); when lLength == 1 and lLastPosition == 0 (so, start position more then end one) To fix this problem we can just change default value of lLastPosition to -2 (so if there is no $ in substitution param we will add substitution itself) Ok, changing initial value of lLastPosition to -2 fixed exception in case of: r = new RE("^a$"); s = r.subst("a", "b", RE.REPLACE_BACKREFERENCES); But in case when input has new lines result after subst also contains new lines. So this: r = new RE("^a$", RE.MATCH_MULTILINE); s = r.subst("\r\na\r\n", "b", RE.REPLACE_BACKREFERENCES); Results in s == "\r\nb\r\n". Is this expected? Vadim I think this is correct behavior because after r = new RE("^a$", RE.MATCH_MULTILINE); s = re.match("\r\na\r\n"); s == "a" (neither "\r\na\r\n", "\r\na" or "a\r\n"), and we replace it with "b" Patches are already applied; closing this bug. |