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 !!
Leave a Reply