javaregexstring

java string matching with regex


I have a specific key i need to match. The key is 10 set's of 4 separated by a dash. The combination can be a combination of letters or numbers.

Example.

aa11-bb22-cc33-44dd-55ee-66ff-gg77-hh88-99ii-jj10

I just want to validate the pattern being 10 sets of 4 separated by a dash.

Probably match this via regex, but I don't know how.

Any help would be appreciated.


Solution

  • ^[a-zA-Z0-9]{4}(?:-[a-zA-Z0-9]{4}){9}$
    

    Try this.See demo.

    http://regex101.com/r/kP8uF5/11