How do I use the inline modifiers instead of RegexOptions.Option?
For example:
Regex MyRegex = new Regex(@"[a-z]+", RegexOptions.IgnoreCase);
How do I rewrite this using the inline character i?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use inline modifiers as follows:
or, inverse the meaning of the modifier by adding a minus-sign:
or, switch them on and off:
Alternatively, you can use the mode-modifier span syntax using a colon
:and a grouping parenthesis, which scopes the modifier to only that group:You can use multiple modifiers in one go like this
(?is-m:text), or after another, if you find that clearer(?i)(?s)(?-m)text(I don’t). When you use the on/off switching syntax, be aware that the modifier works till the next switch, or the end of the regex. Conversely, using the mode-modified spans, after the span the default behavior will apply.Finally: the allowed modifiers in .NET are (use a minus to invert the mode):
xallow whitespace and commentsssingle-line modemmulti-line modeicase insensitivitynonly allow explicit capture (.NET specific)