Menu

#3851 Regex "^" doesn't match start of text when -start is used

obsolete: 8.5b3
closed-duplicate
5
2007-11-20
2007-11-20
No

Tcl versions: 8.4.16, 8.5b1.
macosx 10.4.9

Normally, "^" matches the start of input:

% regexp -line -start 0 {^foo} "foo"
1

When -line is specified, "^" matches the beginning of a line in
the middle of the input:

% regexp -line -start 0 {^foo} "\nfoo"
1

When -start is used, "^" will not match the text at the -start
location:

% regexp -line -start 1 {^foo} "\nfoo"
0

However, "\A" will match there just fine:

% regexp -line -start 1 {\Afoo} "\nfoo"
1

I think the third case is a bug; all four of these examples should match.

Discussion

  • Andreas Kupries

    Andreas Kupries - 2007-11-20

    Logged In: YES
    user_id=75003
    Originator: NO

    Note that the behaviour of the third case is, IIRC, documentend as such ... Yes, regexp.n ...

    -start index
    Specifies a character index offset into the string to start matching the regular expression at.
    When using this switch, `^' will not match the beginning of the line, and \A will still match
    the start of the string at index.

     
  • Andreas Kupries

    Andreas Kupries - 2007-11-20

    Logged In: YES
    user_id=75003
    Originator: NO

    Forgot to say, I know this because I fell into the same trap first and had to rewrite ^ to \A in code of mine where I wanted to use -start to avoid 'string range' and shifting the string down.

     
  • Will Duquette

    Will Duquette - 2007-11-20

    Logged In: YES
    user_id=372859
    Originator: YES

    This is a duplicate of bug 471101.

     
  • Will Duquette

    Will Duquette - 2007-11-20
    • status: open --> closed-duplicate