| Article: |
Network Test Automation with Mac OS X and Tcl | |
| Subject: | incorrect regular expressions | |
| Date: | 2001-10-30 06:59:24 | |
| From: | glennjnn | |
|
The regular expression examples on page 3 of this
article do not match % set myPhoneList "555-1212 nautilus.ipvoice.com" % regexp { ([0-9]+)-([0-9]+) } $myPhoneList matchFound prefix localNumber This does not match because there is no space preceding 555 in $myPhoneList The 800 example is similarly incorrect. In the last example, the "Ethernet|Fddi" one, the regular expression does not have a closing brace}
|
||
Showing messages 1 through 1 of 1.
-
incorrect regular expressions
2001-10-30 11:38:53 mnorton01 [View]



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