I need to find «
in a string with a regex. How would you add that into the following:
String RegExPattern = @"^[0-9a-df-su-z]+\.\s«";
Regex PatternRegex = new Regex(RegExPattern);
return (PatternRegex.M开发者_开发技巧atch(Source).Value);
You should be able to simply use it directly:
var pattern = new Regex("«");
Of course, if used alone you can also use String.IndexOf
instead. If you want to use it in another pattern, as in your question, go ahead. The usage is correct.
If, on the other hand, you also want to allow the named entity, use an alternation:
var pattern = new Regex("(?:«|«)");
Once again, the same can be done in a more complex expression. The ?:
at the beginning of the group isn’t necessary; it just prevents that a capture group will be created for this alternation.
精彩评论