Question on TCL regexp and match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question on TCL regexp and match
# 1  
Old 12-04-2012
Question on TCL regexp and match

Hello everyone,
I'm new in tcl scripting.
I'm currently studying a tcl script and came across this line:

regexp {(\d+)(\S?)} $opts match opt swi

According to my understanding, this line means to search in the opts variable for one or more digit, followed by a non-whitespace character (if the non-whitespace character exists). The matched pattern will then copied into the opt variable.

Is my understanding is correct?
How about the swi? What does it do?

Please help. Thanks
# 2  
Old 12-04-2012
Code:
regexp {(\d+)(\S?)} $opts  match      opt          swi
regexp exp          string ?matchVar? ?subMatchVar subMatchVar ...?



If additional arguments are specified after string then they are treated as the names of variables in which to return information about which part(s) of string matched exp. MatchVar will be set to the range of string that matched all of exp. The first subMatchVar will contain the characters in string that matched the leftmost parenthesized subexpression within exp, the next subMatchVar will contain the characters that matched the next parenthesized subexpression to the right in exp, and so on.
tcl -regexp
# 3  
Old 12-05-2012
Good explanation, thanks spacebar Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. UNIX for Beginners Questions & Answers

TCL script to delete a pattern(regexp)

Hi I am writing a TCL script to delete a certain in a file My Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj; output dk; (1 Reply)
Discussion started by: kshitij
1 Replies

3. Shell Programming and Scripting

Help using regexp in a TCL script ??

In a tcl script I need to find a way of reading a file, and looking for a phrase ("set myvariable") and putting the word following that into a variable. I've used a file open, and a while loop with gets to read each line from the file into a variable, and using regexp searched for the item. I'm... (1 Reply)
Discussion started by: Tonyb61
1 Replies

4. Shell Programming and Scripting

Regexp in tcl

I need to change R3.1.5 as 03015 similarly R4.1.7 as 04017 i need a single command in tcl pls help ---------- Post updated at 05:19 PM ---------- Previous update was at 04:48 PM ---------- i had to do like this without using regexp set old_release "R3.1.5" ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

5. Shell Programming and Scripting

Question on regexp in TCL

I need some help with regexp in tcl. The following code does work if the $urlvar ends in jpg,jpeg,png or gif. Eg, protocol(http/https)://testsite.com/images/image1.jpg if { ! } { //Do something } My problem is that if the URL does not end in these extensions this regexp is of no... (1 Reply)
Discussion started by: ampak
1 Replies

6. UNIX for Dummies Questions & Answers

regexp: match string that contains list of chars

Hi, I'm curious about how to do a very simple thing with regular expressions that I'm unable to figure out. If I want to find out if a string contains 'a' AND 'b' AND 'c' it can be very easily done with grep: echo $STRING|grep a|grep b|grep c but, how would you do that in a single... (9 Replies)
Discussion started by: jimcanoa
9 Replies

7. Shell Programming and Scripting

perl regexp: no match across newlines

Hi. Here's a tricky one (at least to me): I have a file named theFile.txt (UTF-8) that contains the following: a b cWhen I execute perl -pe 's|a.*c|d|sg' theFile.txtin bash 3.2 on MAC OS X 10.6, I get no match, i.e. the result is a b cagain. Any clues why? (2 Replies)
Discussion started by: BatManWSL
2 Replies

8. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies

9. Shell Programming and Scripting

RegExp negative match not working

or I don't know how to make it work ... Hello im trying to build regexp that will match me single string or function call inside of brackets for example I have : <% myFunction("blah",foo) %> or <% myVar %> and not match : <% if(myFunction("blah",foo)==1) %> or <% while(myvar < 3){... (2 Replies)
Discussion started by: umen
2 Replies

10. Shell Programming and Scripting

RegExp question

Hi guys, does anyone know how to test for a regular expression - i want to include it in a script to make sure the variable is a regexp cheers (3 Replies)
Discussion started by: penfold
3 Replies
Login or Register to Ask a Question