开发者

How to find « («) in a string

开发者 https://www.devze.com 2022-12-30 17:06 出处:网络
I need to find &#171 in a string with a regex. How would you add that into the following: String RegExPattern = @\"^[0-9a-df-su-z]+\\.\\s&#171\";

I need to find &#171 in a string with a regex. How would you add that into the following:

String RegExPattern = @"^[0-9a-df-su-z]+\.\s&#171";
Regex PatternRegex = new Regex(RegExPattern);
return (PatternRegex.M开发者_开发技巧atch(Source).Value);


You should be able to simply use it directly:

var pattern = new Regex("&#171");

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("(?:&#171|«)");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消