Find and replace all instances of a pattern in a string using Regular Expressions

Viewed 6009

Using Excel VBA, I'm trying to replace all instances of a simple pattern that looks like this:

{some text}

with some other constant string. So I want to find all the text that is enclosed in curly braces and replace is (with the curly braces) with another string.

I use the following code:

Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "\{.*?\}"
qtext = regEx.Replace(qtext, html_input)

where qtext and html_input are some strings. But this only replaces the first instance of the pattern.

For example:

qtext = "yadda yadda {1:NM:=12.000:0.120} omtty doom {1:NM:=6/6} loppy loop"
html_input = "I am HTML"

And the result should be:

"yadda yadda I am HTML omtty doom I am HTML loppy loop"

But what I get is:

"yadda yadda I am HTML omtty doom {1:NM:=6/6} loppy loop"

What am I missing?

1 Answers
Related