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

Regexp to strip asp tags

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
GB
Hi all is there a way i can strip out the <% and %> and anything in between in a string?

i have tried the regEx.Pattern = "<\%[^>]*\%>"

but i cant get it to escape the % !!

}...the bane of my life!
 
? i use expresso to test regex's - it is very good and free.

your regex works fine in that - so in what environment is it not working and why??
 
Because * is a greedy match, won't it never get to the next % character? Unless you specifically turn off greedy matches.

[^>] Any number of characters that aren't >

% isn't >

now it's at > and it tries to match

\%>

and fails.

You might need to use a negative lookahead

"<\%([^%](?!>))*\%>"

I am doing this mostly from memory, but I *think* the following expression

([^%](?!>))

means, any number of % signs NOT followed by a greater than.

Of course I could be completely wrong, doing this from memory.
 
Hey all, thanks for the responses.
I found the following that worked well...I am a complete noob with regex!!

"<%[\s\S]*?" & Chr(37) & ">"

}...the bane of my life!
 
Ah yes, a lazy match works great. I'm glad my suggestion helped you. What would you have done without me? Grin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top