long strings create endless loop for regexp.execute method

R

redryderridesagain

the following code or something similar creates an endless loop in the
regexp.execute method

dim alongstring as string, mymatches as matchcollection

Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "the pattern here"

' the following loops endlessly with a string that is 1.3 million
characters long
Set myMatches = myRegExp.Execute(alongstring)

any ideas? tkx
 
J

John Nurick

Long strings don't normally cause problems, and nor do quite large
numbers of matches.

Set mymatches = myRegExp.Execute(alongstring)

with a 1,659,696 byte string and a variety of patterns. It took a second
or two to execute, and didn't seem fazed by large numbers of matches (I
got bored after trying a pattern that produced more than 250,000
matches).

On the other hand, it's possible to write patterns that commit the regex
engine to a number of comparisons that increases exponentially with the
length of the string being tested - so conceivably what looks like an
endless loop is in fact a computation that will end normally in a few
days or years or aeons. See e.g. the "Crafting an efficient expression"
chapter of Mastering Regular Expressions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top