Avinash Kumar
Avinash Kumar

Reputation: 777

not able to understand output of regexp in tcl

Please explain the output of this tcl command , i am not getting the result .

on tclsh      
set line = "Clock Domain:               clk"     
regexp {Clock Domain:\s*(.+)} $line tmp1 Pnr_clk
$tmp1 = "Clock Domain:               clk"     
$Pnr_clk = clk

How this value is assigned

Upvotes: 0

Views: 55

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137577

The Tcl regexp command is documented to assign the submatches to the variables whose names you provide. The first such variable you give is tmp1, which gets the whole string that the overall RE matched (which might be a substring of the overall input string; Tcl's RE engine does not anchor matches by default). The second such variable is Pnr_clk, which gets what the first parenthesized sub-RE matches, which in this case is clk because the \s* before the parenthesis greedily consumed the whitespace after Clock Domain:.

Upvotes: 1

Related Questions