开发者

C# Regex Escape Sequences

Is there a complete list of regex开发者_高级运维 escape sequences somewhere? I found this, but it was missing \\ and \e for starters. Thus far I have come up with this regex pattern that hopefully matches all the escape sequences:

 @"\\([bBdDfnreasStvwWnAZG\\]|x[A-Z0-9]{2}|u[A-Z0-9]{4}|\d{1,3}|k<\w+>)"


Alternatively, if you only want to escape a string correctly, you could just depend on Regex.Escape() which will do the necessary escaping for you.

Hint: There is also a Regex.Unescape()


This MSDN page (Regular Expression Language Elements) is a good starting place, with this subpage specifically about escape sequences.


Don't forget the zillions of possible unicode categories: \p{Lu}, \P{Sm} etc.

There are too many of these for you to match individually, but I suppose you could use something along the lines of \\[pP]\{[A-Za-z0-9 \-_]+?\} (untested).

And there's also the simpler stuff that's missing from your list: \., \+, \*, \? etc etc.

If you're simply trying to unescape an existing regex then you could try Regex.Unescape. It's not perfect, but it's probably better than anything you or I could knock up in a short space of time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜