Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A regexp question

29 views
Skip to first unread message

Helmut Giese

unread,
Sep 30, 2022, 10:42:16 AM9/30/22
to
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

Christian Gollwitzer

unread,
Sep 30, 2022, 11:17:36 AM9/30/22
to
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

Helmut Giese

unread,
Sep 30, 2022, 12:33:53 PM9/30/22
to
Christian Gollwitzer <auri...@gmx.de> schrieb:
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
0 new messages