Back To Basics: Use Regular Expression Comments

23 בנובמבר 2008

no comments

Regular expressions are much easier to understand if you use the following syntax and comment each component of the expression by using a number sign (#). To enable comments, you must also specify RegexOptions.IgnorePatternWhitespace, which means that non-escaped white space is ignored.

Regex regex = new Regex(@"

                        ^           # anchor at the start

                       (?=.*\d)     # must contain at least one numeric character

                       (?=.*[a-z])  # must contain one lowercase character

                       (?=.*[A-Z])  # must contain one uppercase character

                       .{8,10}      # From 8 to 10 characters in length

                       \s           # allows a space

                       $            # anchor at the end",





Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>