In. when using regular expressions in. net, some options will be of great help. The options are generally represented by a letter, when using the RegEx class, we can use enumeration or input in the constructor, as shown below:
RegEx r =NewRegEx (@"\ W +", Regexoptions. Compiled | regexoptions. ignorecase );
You can also directly put it in front of the regular expression string in the format
(? {Option List}) {Regular Expression}
For example '(? I) I in ABC 'indicates that the case is ignored, which corresponds to the enumerated regexoptions. ignorecase.
The following describes several common options:
1. Single Row mode: N, regexoptions. singleline
This indicates that the line break can be matched, which is generally used for full-text match. You can make the regular expression match multiple lines of text.
2. Ignore case sensitivity: I, regexoptions. ignorecase
This does not need to be explained much, for example '(? I) abc' can criticize both ABC and ABC.
3. Only group match: N, regexoptions. explicitcapture
Matching unnecessary content will affect performance. We generally use (? : {Expression}) Ignore matching, But if you write too much, it will affect the readability of the regular expression,
Use the N option to make the regular expression match only the group, that is, the form (? <Name> {expression.
4. Ignore spaces and support multi-line Regular Expressions and comments: X, regexoptions. ignorepatternwhitespace
With this option, the blank space in the expression will be ignored. We can only use \ s * or \ s + to match spaces. At the same time, the expression can write multiple rows,
Supports comments starting with #, for example:
RegEx r =NewRegEx (@"(? Six)
\ W + # Name
:
\ W + # Value
");
This option is generally not used, because if it is used, we must replace all spaces in the regular expression with \ s or \ s +, which is troublesome. However, when regular expressions are very complex
Splitting multiple rows and adding comments can enhance the readability of expressions.