If you are looking at string while debugging you will see \\d.
Nothing you can do about that it is suppose to be there.  Debugger
will show the escaped characters, even with @.  If you print out the
string you will only see \d.

It is not compiling to this:
> @"^.*(?=.{10,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&+=]).*$"

It is compiling to this:
> @"^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&+=]).*$"

~Tony


On Aug 17, 8:25 am, xzzy <[email protected]> wrote:
> @"^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&+=]).*$"
>
> compiles to:
>
> @"^.*(?=.{10,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&+=]).*$"
>
> = the compiler is adding an extra backslash in front of \d)(?
>    I don't know how to prevent this from happening
>
> On Aug 17, 12:15 am, Cerebrus <[email protected]> wrote:
>
>
>
> > In C#, you need to escape backslashes with another backslash. I
> > recommend the use of verbatim string literals for complicated strings
> > like this one. (prefix with "@").
>
> > On Aug 17, 3:42 am, xzzy <[email protected]> wrote:
>
> > > Thank you for any help with this problem with Regex and what it
> > > perceives to be an invalid escape sequence.
>
> > > (1) I use this Regex to validate a password:
> > > (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,10})(?=...@#$%^&+=]).*
> > > $     // Length: 6 to 10, letters & numbers
>
> > > it works, but it does not allow the use of: @#$%^&+=
>
> > > (2) So I tried: ^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&
> > > +=]).*$
> > > this works in Javascript,
> > > but in C#, the \d part of the statement does not compile: "Invalid
> > > escape sequence"
>
> > > (3) This compiles:
> > >    ^.*(?=.{10,})(?=.*" + "\\" + "d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&
> > > +=]).*$
> > > but does not work as it compiles to:
> > >    ^.*(?=.{10,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=...@#$%^&+=]).*$
> > > ( an extra backslash before \d)(?   )
>
> > > (4) So I tried: (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,10})(?=...@#
> > > $%^&+=])(?=...@#$%^&+=]).*$
> > > which is #1 above with ".*$" replaced with "(?=...@#$%^&+=]).*$"
> > > It compiles, but does not work, not even for as password as simple as:
> > > Aabbcc5- Hide quoted text -
>
> - Show quoted text -

Reply via email to