Java regex error

Whenever I enter the following...

Pattern pmessage = Pattern.compile("\s*\p{Alnum}[\p{Alnum}\s]*");
Matcher mmessage = pmessage.matcher(message);
Matcher msubject = pmessage.matcher(subject);

I get a Invalid Escape Sequence error. Anyone have any idea why / how I fix this?


For a version of \p{Alpha} that works on the Java native character set instead being stuck unsable to process anything else than legacy data from the 1960s, you need to use

alphabetics = "[\\pL\\pM\\p{Nl]";

For a version of numerics in the same sense, you have to choose which of these you want:

ASCII_digits    = "[0-9]";
all_numbers     = "\\pN";
decimal_numbers = "\\p{Nd}"

because which one applies various depending on circumstances. We’ll assume you copied one of those three to a numeric variable.

Assuming you then want alphanumerics based on the definition above, you could then write:

 alphanumerics = "[" + alphabetics + numerics + "]";

However, if what you mean by alphanumerics is the \w sense of program identifiers, you have to add some stuff.

 identifier_chars = "[\\pL\\pM\\p{Nd}\\p{Nl}\\p{Pc}[\\p{InEnclosedAlphanumerics}&&\\p{So}]]";

This issue is discussed at length in this answer, where you’ll also find a link to some alpha code of mine that does these transforms for you automatically. I hope to get a chance to rewrite it to take up less space this weekend.

Need Your Help

Phone number change across website

php html css

What would be the best way to have a phone number change across a site universally?

Loading NSBundle Plist file to Document Directory

ios iphone

I working with Plist file reading and writing data, To work that in device i have moved plist file from NSBundle to Document Directory programatically. And using that plist to write data. IS this

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.