I'm wondering if the following is possible:
The method Regex.Match
can receive an enum, so I can specify:
RegexOptions.IgnoreCase
RegexOptions.IgnorePatternWhiteSpace
RegexOptions.Multiline
What if I need to specify more than just one? (eg. I want my regex to be Multiline
and I want it to ignore the pattern whitespace).
Could I use |
operator like in C/C++?
You need to annotate it with [Flags]
attribute and use |
operator to combine them.
In the case you mentioned, you can do that because RegexOptions
enum is annotated with it.
A helpful way to use the FlagsAttribute with enumerations
Definition:
[FlagsAttribute]
public enum NewsCategory : int
{
TopHeadlines =1,
Sports=2,
Business=4,
Financial=8,
World=16,
Entertainment=32,
Technical=64,
Politics=128,
Health=256,
National=512
}
Use:
mon.ContentCategories = NewsCategory.Business |
NewsCategory.Entertainment |
NewsCategory.Politics;
Since it is an Enum with a Flags Attribute, you can use:
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhiteSpace | RegexOptions.Multiline
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