Thursday, July 12, 2012

Usage of ?: in TCL


Usage:

?: is used in sub patterns in a regexp
When ever you don’t want a particular subpattern to be included as a sub-pattern use “?:” in front of the sub-pattern

Example:

set string "Projects: Brocade Cisco Fujitsu"

regexp "Projects: (Brocade|Cisco) (?:Fujitsu|Juniper|Cisco) (Fujitsu|Juniper)" $string sub1 sub2 sub3

puts "$sub1\n$sub2\n$sub3\n"

In the above example, the output will be

Projects: Brocade Cisco Fujitsu
Brocade
Fujitsu

The pattern “Cisco” does not come under sub pattern as “?:” is given

The output without ?: would be


Projects: Brocade Cisco Fujitsu
Brocade
Cisco

No comments:

Post a Comment