Specifically to memory here, would Regex.Match() and new Regex().Match() have a difference?
Would not creating a new assertion of the Regex class cost more memory then using Regex.Match?
The reason I am asking is I've always been doing new Regex("pattern").Match("Input") and saw Regex.Match and I'm now questioning if I'm doing it wrong!
With that exact syntax, for you as the developer, there is no difference.
except that new Regex() is not a public constructor, you have to pass a pattern.
So in that case the Static probably better.
Where you would you new Regex() is, to assign it to an instance of a Regex like:
var myregex = new Regex("my pattern");
You can then check things on the instance like timeout MatchTimeout and Options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With