Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression 1

Status
Not open for further replies.

reggler

Programmer
Nov 13, 2008
63
CA
Hey There,

I'm starting to feel kinda weird, seems like i'm the only one having problems with TCL/TK or at least the only one asking for help in this forum :)
Oh well... I'm trying to figure out if a string is applicable or no with a regular expression but i get similart strings but a 0 as ruturn value.
My regexp:
Code:
set result [regexp {"Passed $BIS_Test::total_iterations iterations"} $finaltest::product(device_info)];

$GUI::twidget insert end "\n==== string to apply the pattern: $finaltest::product(device_info)"
            $GUI::twidget insert end "\n==== regexp pattern: 'Passed $BIS_Test::total_iterations iterations'"
            $GUI::twidget insert end "\n==== BIST results: result $result - result2: $result2 ===="

and on the screen i see:

==== string to apply the pattern:

Passed 2 iterations
Failed 0 iterations
>
==== regexp pattern: 'Passed 2 iterations'
==== BIST results: result 0 - result2: 0 ====

So why does it not rocognize my string: "Passed 2 iterations"?
I'm sorry if I'm just stealing your valuable time with my dummy questions but i really appreciate the help you guys provide! It's saved me lots of headache!
Thanks!
 
Don't be put off. The volume of posts ebbs and flows around here.

As usual, the answer is in the precedence of substitution. When you have variable substitution, "$varname", embedded in delayed substitution, "{...$varname...}", what get's put in the substituted string is $varname. You would need to enforce substitution later in order to get the value of the variable.

In this case, I think I would use an RE pattern variable:
set re "Passed $BIS_Test::total_iterations iterations"
Then:
set result [regexp $re $finaltest::product(device_info)]

_________________
Bob Rashkin
 
This code does what you want:
Code:
set finaltest "Passed 120 iterations"
set result [regexp {Passed\s(\d+)\siterations} $finaltest match numiter];

puts "String to apply the pattern: '$finaltest'"
puts "result=$result"
puts "This was matched: $match"
puts "Number of iteration (extracted): $numiter"

The result is:
Code:
String to apply the pattern: 'Passed 120 iterations'
result=1
This was matched: Passed 120 iterations
Number of iteration (extracted): 120
As you see the matching result=1 and as a special bonus for you I extracted the number of iteration
:)
 
Hi

reggler said:
I'm sorry if I'm just stealing your valuable time with my dummy questions but i really appreciate the help you guys provide!
Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank ***
for this valuable post![/navy]


at the bottom of the helpful member's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top