Reputation: 859
I am trying to find the following text in my string : '***'
the thing is that the C# Regex mechanism doesnt allow me to do the following:
new Regex("***", RegexOptions.CultureInvariant | RegexOptions.Compiled);
due to
ArgumentException: "parsing "*" - Quantifier {x,y} following nothing."
obviously it thinks that my stars represents regular expressions, is there a way to tell the Regex mechanism to treat stars as just stars and nothing else?
Upvotes: 12
Views: 38353
Reputation: 10347
*
in Regex
means:
Matches the previous element zero or more times.
so that, you need to use \*
or [*]
instead.
explain:
\
When followed by a character that is not recognized as an escaped character in this and other tables in this topic, matches that character. For example,
\*
is the same as\x2A
.
[ character_group ]
Matches any single character in
character_group
.
Upvotes: 21