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

Need help with expect (tcl) regular expression

349 views
Skip to first unread message

Ray Muforosky

unread,
Jul 12, 2006, 11:55:40 AM7/12/06
to
I'm having problem tracking this string "VXUJT-12#" . it could be any 2
digit number ending with a pound sign ( a dash followed by 2 digits and
a #). I need help catching it using -re:

expect {
-re {(*\-\d\d\#$)} { break}
"invalid input" { puts "Wrong input"; exit}
}

Thanks in advance for your help.

Jonathan Bromley

unread,
Jul 12, 2006, 12:00:33 PM7/12/06
to
On 12 Jul 2006 08:55:40 -0700, Ray
Muforosky <muf...@gmail.com> wrote:

> -re {(*\-\d\d\#$)} { break}

I suspect you meant (.*-\d\d\#$)

In an RE, "*" on its own just means "one asterisk". And unless I'm
mistaken, you don't need to escape the hyphen.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.

Michael A. Cleverly

unread,
Jul 12, 2006, 1:17:59 PM7/12/06
to
On Wed, 12 Jul 2006, Jonathan Bromley wrote:

> On 12 Jul 2006 08:55:40 -0700, Ray
> Muforosky <muf...@gmail.com> wrote:
>
> > -re {(*\-\d\d\#$)} { break}
>
> I suspect you meant (.*-\d\d\#$)
>
> In an RE, "*" on its own just means "one asterisk". And unless I'm
> mistaken, you don't need to escape the hyphen.

Actually * means zero to many of the preceeding atom. In this case there
isn't one and the regexp won't even compile:

% regexp {(*\-\d\d\#$)} foo-42#
couldn't compile regular expression pattern: quantifier operand invalid

Michael

Jonathan Bromley

unread,
Jul 12, 2006, 1:24:23 PM7/12/06
to
On Wed, 12 Jul 2006 11:17:59 -0600, "Michael A. Cleverly"
<mic...@cleverly.com> wrote:

>On Wed, 12 Jul 2006, Jonathan Bromley wrote:

>> In an RE, "*" on its own just means "one asterisk".

No, it doesn't...

>Actually * means zero to many of the preceeding atom.

Indeed it does. Blush. Blame old age.

At least my fix was right ;-)

ms

unread,
Jul 13, 2006, 4:02:32 PM7/13/06
to
>>> -re {(*\-\d\d\#$)} { break}
>>
>>I suspect you meant (.*-\d\d\#$)
>>
>>In an RE, "*" on its own just means "one asterisk". And unless I'm
>>mistaken, you don't need to escape the hyphen.
>
>
> Actually * means zero to many of the preceeding atom. In this case there
> isn't one and the regexp won't even compile:
>
> % regexp {(*\-\d\d\#$)} foo-42#
> couldn't compile regular expression pattern: quantifier operand invalid
>
> Michael

What about:
-re ".*-\[0-9\]\[0-9\]#$" { ...

or even
-re "\[A-Z\]+-\[0-9\]\[0-9\]#$" { ...

second regular if only we expected upper characters like "VXUJT-12#".

But I have a question, because I noticed that you used regular like
"\d", is it mean digit ? Which version of regular is able to work with it?

Regards
Sebastian

Bruce Hartweg

unread,
Jul 13, 2006, 5:02:06 PM7/13/06
to
ms wrote:

> But I have a question, because I noticed that you used regular like
> "\d", is it mean digit ? Which version of regular is able to work with it?
>

yes it does, there are numerous shorthand escapes which are all documented
on the re_syntax man page in the ESCAPES section
http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm#M28
These arrived in 8.1 if I recall correctly

Bruce

ms

unread,
Jul 13, 2006, 5:39:04 PM7/13/06
to
>>
> yes it does, there are numerous shorthand escapes which are all documented
> on the re_syntax man page in the ESCAPES section
> http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm#M28
> These arrived in 8.1 if I recall correctly
>
> Bruce

Thanks a lot for answer and link. It will check my view at re from now.

Sebastian

0 new messages