Java Regex for Trademark Symbol Validation

In this java regex example, we will learn to match trademark symbol ™.

The Unicode code point U+2122 represents the “trademark sign” character. You can match this with “\u2122”, “\u{2122}”, or “\x{2122}”, depending on the regex flavor you’re working with.

Solution java regex : \u2122

String data1 = "Searching in trademark character ™ is so easy when you know it.";
  
  String regex = "\u2122";
  
  Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  Matcher matcher = pattern.matcher(data1);
  while (matcher.find())
  {
     System.out.print("Start index: " + matcher.start());
     System.out.print(" End index: " + matcher.end() + " ");
     System.out.println(matcher.group());
  }
}

Output:

Start index: 33 End index: 34 ™

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.