I have a Regex object created with the new Regex(string pattern)
constructor, is there a way afterwards to see what pattern the regex object was created with?
I can't seem to be able to access the "pattern" string member in either the Regex or in RegexOptions
objects.
Context: Reason I'm asking is I'm creating a few regex objects early on while initializing (patterns are stored in a config file), they then get passed to a different class to be used frequently. However, I also need to compare the pattern string to those stored in a SQL database at run-time.
I would prefer not having to pass a string with the pattern in addition to the regex object. I also feel that creating the object once at startup is not a bad idea since the regex will be reused hundreds of times?
Feel free to provide alternative advices.
* - means "0 or more instances of the preceding regex token"
RegExp Object A regular expression is a pattern of characters. The pattern is used to do pattern-matching "search-and-replace" functions on text. In JavaScript, a RegExp Object is a pattern with Properties and Methods.
So, in the debugger hovering the cursor over a regex object was showing the pattern, so it had to be close. Turns out Regex.ToString() returns the pattern.
ToString: Returns the regular expression pattern that was passed into the Regex constructor.
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