Sumanth_newbie Sumanth_newbie - 1 year ago 74
Java Question

What is the regex pattern that can match for ASCII and explicit currency symbols

I'm new to regex and tried searching few regex related questions here. But couldn't find the solution.

I want to check if the String contains only the below:

1) ASCII characters(Currently using

for ASCII alone) or

2) The following currency symbols:

I know that the currency symbols are not from ASCII, but we can get those values from html and using
and hence want any regex pattern to match only if any of the above conditions are satisfied.

My requirement is :

If the string has any character other than ASCII and the given symbols, it should return

Answer Source

If you look at the javadoc of the Pattern class, you will see that there is a character class for ASCII codes. So your code could be something like:

Stirng input = ...;
boolean isValid = input.matches("[₺£€\\p{ASCII}]*");

That's assuming you want to accept any ASCII character.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download