Java Regex for Currency Symbols

In this tutorial, we will learn to match all available currency symbols, e.g. $ Dollar, € Euro, ¥ Yen, in some text content.

Solution Regex :  \\p{Sc}

Example Code for matching any Currency Symbol using Java Regex

String content = "Let's find the symbols or currencies : $ Dollar, € Euro, ¥ Yen";
      
String regex = "\\p{Sc}";

Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
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: 39 End index: 40  : $
Start index: 49 End index: 50  : €
Start index: 57 End index: 58  : ¥

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.