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

Replace all values between two characters

Status
Not open for further replies.
Feb 20, 2001
24
US
Hi,
I'm looking for a way to replace all characters between two other characters in a string with some other value. So say I have

string = "adklfjadlkfdf{123}akldjfadklfjadklf{33333}kaldfjadkf{3}akdlfjad"

I would want to replace each set of characters in between each { and } with something else lets say "blah"

so my result would be

"adklfjadlkfdf{blah}akldjfadklfjadklf{blah}kaldfjadkf{blah}akdlfjad"

What would be the easiest way to do this? Thanks in advance and let me know if you need more information.
 
so the data to replace is always between "{}" ?
 
example...
Code:
<%
dim Str,RE
set RE=New RegExp

Str = "adklfjadlkfdf{123}akldjfadklfjadklf{33333}kaldfjadkf{3}akdlfjad"
    RE.global=true
    RE.pattern="\{\d*\}"
Str=RE.replace(Str,"{blah}")
%>

<%=Str%>
 
If you want to replace strings which are not just numbers, then try:

\{[^\}]*\}

for the regex pattern.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top