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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regexp & regsub

Status
Not open for further replies.

BGH2104

Programmer
Jul 24, 2003
3
MY
Hello,
I have a question on regexp & regsub.Actually, I have read the tutorial on internet about regexp & regsub.But I still can't understand how to apply this code.

I just want to take only sub string from the string.Example:

Input:
activate%NAME%batch%5050%GH%TYPE=TRUE;

Output:
GH%TYPE=TRUE; and replace the '%' symbol to ':'

The last result:
GH:TYPE=TRUE;

Pls assist me on how to settle this problem.

Thanks.

 
Code:
set str "activate%NAME%batch%5050%GH%TYPE=TRUE;"
activate%NAME%batch%5050%GH%TYPE=TRUE;
(mars) 50 % if {[regexp ".*(GH.*)" $str all mat]} {
                regsub -all "%" $mat  ":" mat
            }
1
(mars) 51 % puts $mat
GH:TYPE=TRUE;
(mars) 52 %
 
Thank you.

But, how about if the "%GH%%TYPE=TRUE;" is change to another words. By example:

activate%NAME%batch%5051%CANCEL%RIGHT=TRUE;
or
activate%NAME%batch%5051%PLEASE%RIGHT=TRUE;

How do I wite on my programme?

 
Hello again,

My Friend has told me to do like this. And it works as I need.

Sample:

set str "activate%NAME%batch%5050%CANCEL%TYPE=TRUE;"

puts $str

if {[regexp "(.*)%(.*)%(.*)%(.*)%(.*)%(.*)" $str all a b c d e f ]} {
puts "$e:$f"
}


OUTPUT:

activate%NAME%batch%5050%CANCEL%TYPE=TRUE;
CANCEL:TYPE=TRUE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top