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
Post a Comment