Find and Replace with Regex seems broken
Regex find and replace in LINQPad doesn't seem to use standard regex syntax. I'm having to escape my quotes and can't use question marks in my expressions.
Here's the code I'm working with:
public class Something { public string[] Strings { get; set; } = { "One", "Two", "Three" }; public string Name { get; set; } }
And the pattern: ^(\s+)public .*? (\w+).*?"(.*?)"
When I click find, I get the "specified text was not found" dialog.
If I remove the question marks and escape the quotes, it works, but without the question marks, the capture groups are incorrect:
Regex in .net works as expected:
var code = @"public class Something { public string[] Strings { get; set; } = { ""One"", ""Two"", ""Three"" }; public string Name { get; set; } }".Dump("Code"); var pattern = @"^(\s+)public .*? (\w+).*?""(.*?)""".Dump("Pattern"); Regex.Match(code, pattern, RegexOptions.Multiline).Dump("Match"); Regex.Replace(code, pattern, "\n\n1: $1\n2: $2\n3: $3\n\n", RegexOptions.Multiline).Dump("Replace");
I'm using LIQNPad 7.6.6
Comments
It looks like LINQPad's using Actipro's built in regex engine that lacks the "lazy" operator and adds quoted literal strings:
https://www.actiprosoftware.com/docs/controls/winforms/syntaxeditor/regular-expressions/language-elements
That's right. The user interface isn't very helpful, here. I'll improve this in the next build. I'm not sure what I can do about no support for the lazy operator, though.
It seems unfortunate (bad?) that Actipro chose to implement their own Regex engine rather than use the one already built into .Net and that has lots of very smart people optimizing. Perhaps you can implement a .Net based Regex search / replace instead of using Actipro's?