java - How to create a Regex to find exact String length? -


having these cases:

  • 12345678901234
  • 123456789012345
  • 1234567890123456
  • 12345678901234567

i need find string has exact 15 chars length.

until made code:

string pattern = "(([0-9]){15})"; mathcer m = new mathcer(pattern); if (m.find()){     system.out.println(m.group(1)); } 

the results this:

  • 12345678901234 (not found good)
  • 123456789012345 (found good)
  • 1234567890123456 (found not good)
  • 12345678901234567 (found not good)

how can create regex can give me result of exact 15 thought regex can give me. more 15 not acceptable.

simply use matches() instead of 'find()'


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -