Click here to Skip to main content
14,977,910 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
I have this code:

And I get this error:
Invalid escape sequence in ^[SFTG]\d{7}[A-Z]$

How can I solve this error?
Updated 12-Dec-14 4:13am

The string containing you regular expression has a backslash in it:

Pattern .compile("^[SFTG]\d{7}[A-Z]$");

It should look like this instead:

Pattern .compile("^[SFTG]\\d{7}[A-Z]$");
//                       ^^-------------- Double backslash needed here because backslash is an escape character in strings.

See also here:[^]


Maciej Los 17-Nov-14 13:41pm
And what does your answer differs from mine, Manfred?
Manfred Rudolf Bihy 17-Nov-14 15:22pm
I didn't read your solution, sorry!
Maciej Los 17-Nov-14 16:00pm
Not to worry ;)
+5! for direct instructions...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900