Sairam Sairam - 4 months ago 7
Java Question

Regex pattern For alphanumerics,//,* and decimal points up to 2 points

I want to match a text which has alphanumerics, slash (

/
), asterisk (
*
) and decimal (
.
) up to two points like
100.00
but not
100.000
.

I have tried
[0-9A-Za-z/.*]
I have Just kept
(.*)
which is accepting everything. but it shouldn't be like that. It should be something like (./d{2}) for accepting only 2 digits after decimal(.)

Example of what I want to match:

GHJ1234*BVC/100.00

Answer

This matches the string you provided in the comments:

\w+\*\w+/\d+\.\d{2}

Try it here


Make sure when you put it in your Java code to escape all the backslashes:

 \\w+\\*\\w+/\\d+\\.\\d{2}