A fellow user of the Regex Hero tool pointed out that the multiline option wasn't behaving as expected. In the following scenario with multiline turned on you'd expect every line to be highlighted:
Regular expression:
^test$
Target string:
test
test
test
Well, as it turns out none of those lines were highlighted and I found out why. Apparently the .NET regex engine looks for the start of new lines based on line feeds rather than carriage returns. So behind the scenes I'm now replacing carriage returns with line feeds within both the regular expression and the target string. This solves the problem and allows multiline mode to behave more like it should. Thank you Ed for letting me know about this.
The other little change I've made is concerning trailing whitespace. A co-worker pointed out that it's easy to overlook trailing whitespace in your regular expression. And since most of the time you're not going to purposely put spaces or carriage returns at the end of your regular expression, I added a warning that simply says, "Trailing whitespace detected."
Regular expression:
^test$
Target string:
test
test
test
Well, as it turns out none of those lines were highlighted and I found out why. Apparently the .NET regex engine looks for the start of new lines based on line feeds rather than carriage returns. So behind the scenes I'm now replacing carriage returns with line feeds within both the regular expression and the target string. This solves the problem and allows multiline mode to behave more like it should. Thank you Ed for letting me know about this.
The other little change I've made is concerning trailing whitespace. A co-worker pointed out that it's easy to overlook trailing whitespace in your regular expression. And since most of the time you're not going to purposely put spaces or carriage returns at the end of your regular expression, I added a warning that simply says, "Trailing whitespace detected."
Comments
Post a Comment