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

Possible bug in regexp

47 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 5, 2017, 1:59:06 AM12/5/17
to
When doing:
regexp -line ${checkLine} ${currentRow} values

This gives a match and fills values.

When I do:
regexp -line ${checkLine} "${currentRow} 12" values

This does not give a match and it leaves values untouched.

Is this as it should be? I would expect values to be empty.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Rich

unread,
Dec 5, 2017, 5:46:13 AM12/5/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> When doing:
> regexp -line ${checkLine} ${currentRow} values
>
> This gives a match and fills values.
>
> When I do:
> regexp -line ${checkLine} "${currentRow} 12" values
>
> This does not give a match and it leaves values untouched.
>
> Is this as it should be? I would expect values to be empty.

The operation is implied by the wording of the manpage:

MatchVar will be set to the range of string that matched all of
exp.

Implying that when there is "no match" there is "no set".

In any case, when not using the -inline flag it is better to check the
return value from regex to determine match/no-match states than to look
for the match/submatch vars afterward.

Cecil Westerhof

unread,
Dec 5, 2017, 7:28:07 AM12/5/17
to
OK, thanks for the explanation.

keithv

unread,
Dec 5, 2017, 3:23:05 PM12/5/17
to
On Tuesday, December 5, 2017 at 2:46:13 AM UTC-8, Rich wrote:
I often exploit this behavior. I put a default value into the MatchVar knowing if the regex doesn't match then it won't be over-written.

Contrived example:
set myDate [clock seconds]
regexp {TimeStamp: (\d+)} $logData . myDate
0 new messages