Question on regexp in TCL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question on regexp in TCL
# 1  
Old 12-26-2012
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

Code:
if { ![regexp -nocase {(jpg|jpeg|png|gif)$} $urlvar]  }  {
        //Do something
}

My problem is that if the URL does not end in these extensions this regexp is of no use. For eg, how to make this work for a URL with query strings or anything else afer the extension
Eg:
Code:
protocol(http/https)://testsite.com/images/image1.jpg?height=100&width=80

Help will be appreciated.

Last edited by Scott; 12-26-2012 at 06:34 PM.. Reason: Code tags
# 2  
Old 12-26-2012
How about:
Code:
if { [regexp -nocase {\.(jpg|jpeg|png|gif)$|\?} $urlvar] }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

TCL - Question regarding Braces {}

Hello everyone, What is the difference between these two tcl commands: (A) --> puts "ERROR!!! ${current_name}/${opt} is not found." (B) --> puts "ERROR!!! $current_name/$opt is not found." Are the braces needed to be put? Or both A and B has the same output? (5 Replies)
Discussion started by: mar85
5 Replies

5. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: mar85
2 Replies

6. Programming

Tcl question

Hello guys, please help me I want to use TCl to move the lines with line number as odd number to a new file source_odd.txt, and move the lines with character 'a' to another file source_a.txt. I also want to create a tcl function to list all the file names in a appointed directory. (1 Reply)
Discussion started by: kunleoyafajo
1 Replies

7. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 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 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

10. Shell Programming and Scripting

few TCL question

Hello I am a TCL beginer, so please answer accordingly here are my question: 1. variable scope I built a text widget and gave it a textvariable: cmd_entry, I I sent it to a procedure where I declare it as “global cmd_entry” and give it a value The problem is that in the main program... (0 Replies)
Discussion started by: orid
0 Replies
Login or Register to Ask a Question