本文主要是介绍Tcl regexp和regsub,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.regexp
regexp 是用于判断正则表达式是否全部或者部分匹配目标字符串的命令,匹配返回1,否则返回0
regexp 正则表达式 string
2.regsub
regsub 是用于对目标字符串中满足正则表达式的部分进行替换,并将替换后的结果存入新的变量中,匹配成功返回1,否则返回0
regsub 正则表达式 string 替换
regsub there "They live there lives" their
set libcell_lists [lsort -increasing [get_object design.insts.libcell.nameFullHier -u]]
set cell_number [get_object design.cntInsts]
set libcell_lists_number [llength $libcell_lists]echo "The total numbet of cell types are $libcell_lists_number" > libcell_count.txt
echo "The total number of cell are $cell_number" >> libcell_count.txt
echo "The total number of cell types are $libcell_lists_number" > libcell_type_count.txt
echo "The total number of cell are $cell_number" >> libcell_type_count.txtset cell_number [expr $cell_number * 1.0]foreach cell $libcell_lists {set inst_number [llength [get_object design.insts.libcell ".nameFullHier == $cell"]]set inst_precent [expr $inst_number / $cell_number * 100]echo "$cell : $inst_number $inst_precent%" >> libcell_count.txt
}set cell_type_list ""
foreach cell $libcell_lists {if {[regexp {D0P} $cell] | [regexp {D1p} $cell]} {set cell_new [regsub {D([0-9][A-Z][0-9]BWP)} $cell "D*BWP"]} else {set cell_new [regsub {D([0-9]+)BWP} $cell "D*BWP"]}lappend cell_type_list $cell_new
}set cell_type_list_1 [lsort -unique $cell_type_list]foreach cell $cell_type_list_1 {echo "$cell"set inst_number [llength [get_object sesign.insts.libcell ".nameFullHier =~ $cell"]]set inst_precent [expr $inst_number / $cell_number * 100]echo "$cell : $inst_number $inst_precent%" >> libcell_type_count.txt
}
这篇关于Tcl regexp和regsub的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!