Bug 18515 - Line anchor does not work when match starts at index > 0
Summary: Line anchor does not work when match starts at index > 0
Status: CLOSED WONTFIX
Alias: None
Product: Regexp
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P3 major (vote)
Target Milestone: ---
Assignee: Jakarta Notifications Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-31 12:20 UTC by Pete Hendry
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pete Hendry 2003-03-31 12:20:00 UTC
When using the RE.match( String text, int pos ) method with a pattern that 
uses the start of line anchor '^', the match does not work from the start 
location. For example, if I have the pattern

  "^el"

and I run

  match( "hello", 1 )

then the match should succeed as the start location is effectively the start 
of the string I want matched against (i.e. the use for this is to save doing a 
substring and passing the result instead of the whole string and an index). 
With the current functionality it only succeeds as a start-of-line for index 
== 0. The corresponding line of code is

                case OP_BOL:

                    // Fail if we're not at the start of the string
                    if (idx != 0)

I have done a fix that records that startPos in match(String, int) and 
compares idx to this but do not know if this would have any side-effects so 
have not included it as a fix. Without this functionality the usefulness of 
this version of the match method is reduced.
Comment 1 Oleg Sukhodolsky 2003-10-25 19:39:48 UTC
In this case jakarta-regexp behaves the same way as gnu-regexp library and 
Sun's java.util.regex.
It looks like they consider RE.match(int) (in jakarta&gnu) and Matcher.find(int)
(in java.util.regex) as a way to repeat search from some position
but not as search in substring.  Ans so, they do not match starting position as
line start.

I'd say this bug should be closed as not a bug.
BTW, there is a simple workaround:
use RE.match(string.substring(position)) instead of RE.match(string, position)
if you want match start of substring as start of line.
Comment 2 Vadim Gritsenko 2003-12-19 03:25:00 UTC
Marking as WONTFIX