• A regexp question

    From Helmut Giese@21:1/5 to All on Fri Sep 30 16:42:11 2022
    Hello out there,
    I know that I am not a regexp guru but usually I get along and manage
    somehow to reach what I am after. But the example below leaves me
    stunned:
    ---
    set line { | {NUMBER} {return [mkLeaf NUMBER $1]}}
    set patt {|\s+{(.+)}\s+\{}
    regexp $patt $line -> lhs ;# this returns '1'
    set -> ;# this is empty
    set lhs ;# as is this
    ---
    How can this be? 'regexp' returning '1' but the matchvar(s) are empty?
    This comes as a complete blow to my understanding of 'regexp'.
    A very confused
    Helmut
    PS: This is on Windows with Tcl 8.6.10

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Fri Sep 30 17:13:08 2022
    Am 30.09.22 um 16:42 schrieb Helmut Giese:
    set line { | {NUMBER} {return [mkLeaf NUMBER $1]}}
    set patt {|\s+{(.+)}\s+\{}
    regexp $patt $line -> lhs

    The | is a regexp metacharacter for branching. The regexp matches the
    empty string at the beginning of your line:

    (chris) 58 % regexp $patt ""
    1

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to Christian Gollwitzer on Fri Sep 30 18:33:48 2022
    Christian Gollwitzer <auriocus@gmx.de> schrieb:

    Am 30.09.22 um 16:42 schrieb Helmut Giese:
    set line { | {NUMBER} {return [mkLeaf NUMBER $1]}}
    set patt {|\s+{(.+)}\s+\{}
    regexp $patt $line -> lhs

    The | is a regexp metacharacter for branching. The regexp matches the
    empty string at the beginning of your line:

    (chris) 58 % regexp $patt ""
    1

    Christian
    Thanks Christian,
    I didn't know that. I must have read it, some time in the past, but
    have, I believe, never used it and so it didn't stick.
    Phew, I am really relieved.
    Thanks again and have a nice weekend
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)