Raghu
Raghu

Reputation: 1161

Regex pattern in java

What would be a regex pattern for the following ' and ® in Java. I have tried the following but have not been successful

  1. &#[0-1][0-1][0-1]
  2. &#\d\d

Upvotes: 0

Views: 706

Answers (2)

Ina
Ina

Reputation: 4470

Ok, then it should be:

str.matches(".*&#\\d{1,3};.*"); 

This matches &# followed by 1, 2 or 3 digits and then a ;)

Upvotes: 2

crowne
crowne

Reputation: 8534

These should work:

  1. ".*\\x27.*" matches an embedded apostrophe
  2. ".*\\xae.*" matches an embedded registered trademark symbol

I tested with String.match

If you need longer unicode values you can use

  1. ".*\\u0027.*" matches an embedded apostrophe
  2. ".*\\u00ae.*" matches an embedded registered trademark symbol

See http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html

Upvotes: 0

Related Questions