In Python, we have the re.VERBOSE argument that allows us to nicely format regex expressions and include comments, such as
import re
ric_index = re.compile(r'''(
^(?P<delim>\.) # delimiter "."
(?P<root>\w+)$ # Root Symbol, at least 1 character
)''',re.VERBOSE)
Is there something similar in C#?
You can use verbatim string (using @), which allow you to write:
var regex = new Regex(@"^(?<delim>\\.) # delimiter "".""
(?<root>\\w+)$ # Root Symbol, at least 1 character
", RegexOptions.IgnorePatternWhitespace);
Note the use of RegexOptions.IgnorePatternWhitespace option to write verbose regexes.
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