Daniel B. Daniel B. - 16 days ago 5
Java Question

Java - Regex only 0 or 5



Regular expression only accepts 0 or 5.

Is there a regex expression to evaluate that?

Thanks.

Answer

You can use either "0|5" or "[05]". The first is an alternative, the second is a character class. They will behave identically. See the documentation for Pattern for more information on the building blocks for regular expressions.