I have some useful regular expressions in Perl. Is there a simple way to translate them to .NET’s dialect of regular expressions?
If not, is there a concise reference of differences?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a big comparison table in http://www.regular-expressions.info/refflavors.html.
Most of the basic elements are the same, the differences are:
Minor differences:
\u200A, in Perl it is\x{200A}.\vin .NET is just the vertical tab (U+000B), in Perl it stands for the “vertical whitespace” class. Of course there is\Vin Perl because of this.(?(name)yes|no), but(?(<name>)yes|no)in Perl.Some elements are Perl-only:
x?+,x*+,x++etc). Use non-backtracking subexpression ((?>…)) instead.\N{LATIN SMALL LETTER X},\N{U+200A}.\l(lower case next char),\u(upper case next char).\L(lower case),\U(upper case),\Q(quote meta characters) until\E.\pLand\PL. You have to include the braces in .NET e.g.\p{L}.\X,\C.\v,\V,\h,\H,\N,\R\g1,\g{-1}. You can only use absolute group index in .NET.\g{name}. Use\k<name>instead.[[:alpha:]].(?|…)\K. Use look-behind ((?<=…)) instead.(?{…}), post-poned subexpression(??{…}).(?0),(?R),(?1),(?-1),(?+1),(?&name).(?{…})(R),(R1),(R&name)(DEFINE).(*VERB:ARG)(?P<name>…). Use(?<name>…)instead.(?P=name). Use\k<name>instead.(?P>name). No equivalent in .NET.Some elements are .NET only:
\Kinstead.(?(pattern)yes|no).[a-z-[d-w]](?<-name>…). This could be simulated with code evaluation assertion(?{…})followed by a(?&name).References: