ID:2051705
 
Resolved
Regular expressions with zero-width matches misbehaved in some cases.
BYOND Version:510.1331
Operating System:Windows 10 Pro 64-bit
Web Browser:Firefox 44.0
Applies to:Dream Daemon
Status: Resolved (510.1332)

This issue has been resolved.
Descriptive Problem Summary:
Given a regex that can successfully match nothing, (with the "g"lobal flag) replacetext will freeze the world. Interestingly, the UI remains responsive, but executing other verbs does nothing.

Additionally, manually looping through such a regex does not match the final position in the string. (See Test4 below)

Code Snippet (if applicable) to Reproduce Problem:
client/verb
Test1()
world << replacetext("aaaaaaaa", regex(""), "N")
// Actual: "Naaaaaaaa". Correct!

Test2()
world << replacetext("Hello_World", regex("_*", "g"), "")
// Actual: Freezes the world (but not the UI)
// Expected: "HelloWorld" See: https://regex101.com/r/hL6tY3/1

Test3()
world << replacetext("aaaaaaaa", regex("()", "g"), "N") // Used "()" instead of "" because of Regex101
// Actual: Freezes the world (but not the UI)
// Expected: "NaNaNaNaNaNaNaNaN" Batman! See: https://regex101.com/r/cH0fY9/1

Test4()
var/regex/R = regex("()", "g")
world << "Match at positions: \..."
while(R.Find("hi"))
world << "[R.index] \..."
world << ""
// Actual: "Match at positions: 1 2"
// Expected: "Match at positions: 1 2 3" See: https://regex101.com/r/mC6fU7/1


Disclaimer:
I recognize some of the examples are silly, but I wanted them to be fairly minimal. In my particular case, I needed to match any leading whitespace, followed by an optional quotation mark. Since both parts were optional, it lead to the world freezing.
Huh, I tested zero-width cases. I'll take a look soon.
Lummox JR resolved issue with message:
Regular expressions with zero-width matches misbehaved in some cases.