advertisement

Article:
  Network Test Automation with Mac OS X and Tcl
Subject:   incorrect regular expressions
Date:   2001-10-30 11:38:53
From:   mnorton01
Response to: incorrect regular expressions

hi,


Good catch. The braces with space padding must have been reformatted for the article. Yes,
these were tested. Somehow I must have mangled them when I cut and pasted into Word from tclsh. Here's the formatting bug scrub.


thanks,


Mike


Example nautilus.ipvoice.com


set myPhoneList "555-1212 nautilus.ipvoice.com"
regexp {([0-9]+)-([0-9]+)} $myPhoneList matchFound prefix localNumber


% set myPhoneList "555-1212 nautilus.ipvoice.com"
555-1212 nautilus.ipvoice.com
% regexp {([0-9]+)-([0-9]+)} $myPhoneList matchFound prefix localNumber
1
% puts $prefix
555
% puts $localNumber
1212


Example 800 Number


set myPhoneList "(800) 555-1212 nautilus.ipvoice.com"
regexp {(\([0-9]+\) )?([0-9]+)-([0-9]+)} \
$myPhoneList matchFound areaCode prefix localNumber
puts "$areaCode $prefix $localNumber"


% set myPhoneList "(800) 555-1212 nautilus.ipvoice.com"
(800) 555-1212 nautilus.ipvoice.com
% regexp {(\([0-9]+\) )?([0-9]+)-([0-9]+)} \
$myPhoneList matchFound areaCode prefix localNumber
1
% puts "$areaCode $prefix $localNumber"
(800) 555 1212
%



Example Get Interface Status


set myRouterInt "Ethernet1/0 121.1.1.2 YES manual up up"
regexp {(Ethernet|Fddi)([0-9])/([0-9]) .*(up|down)} \
$myRouterInt match int_type slot_id port_id int_status


% set myRouterInt "Ethernet1/0 121.1.1.2 YES manual up up"
Ethernet1/0 121.1.1.2 YES manual up up
% regexp {(Ethernet|Fddi)([0-9])/([0-9]) .*(up|down)} \
$myRouterInt match int_type slot_id port_id int_status
1
% put "$int_type $slot_id $port_id $int_status"
Ethernet 1 0 up