java - String.matches() return false unexpectedly. -
i'm trying write programme interprets race results. in order need utilize regex test if strings match pattern using string.matches(string regex) method. when using methods strings expect homecoming true, homecoming false instead.
using next string regex pattern, of strings homecoming true , other false when should homecoming true well:
regex = "[ ]*[1-9]+[ ]+[a-za-z]+[ ]+[a-za-z]+[ ]+[a-za-z]+[ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[1-9]+[ ]+[1-9]+[ ]+[0-9:.]+[ ]+" these of strings homecoming true string.matches(string regex) method:
" 1 ryan kepshire crown point 31 4 16:31 " " 2 matthew mosak crown point 34 4 16:44 " " 3 dylan wallace crown point 36 4 16:58 " " 4 nicholas zak hanover central 51 6 17:08 " " 5 joshua whitaker crown point 37 4 17:16 " " 8 collin allen hobart 64 8 17:23 " " 9 zachary hoover crown point 29 4 17:29 " these of strings homecoming false string.matches(string regex) method:
" 6 christopher ramos river forest 103 12 17:18 " " 7 boyer hunter lowell 78 10 17:20 " " 10 miguel tapia merrillville 98 11 17:32 " i need help determining why bottom 3 strings fail regex test while top 7 pass it.
[ ]*[0-9]+[ ]+[a-za-z]+[ ]+[a-za-z]+[ ]+[a-za-z]+[ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[a-za-z]*[ ^ ]?[a-za-z]*[ ]?[a-za-z]*[ ]?[0-9]+[ ]+[0-9]+[ ]+[0-9:.]+[ ]+ ^ ^
your regex not allow 0 in integers.that why failing.see here.
http://regex101.com/r/uh3tp3/5
i have modified take 0.
ex. [1-9]+ not take 10.
" 6 christopher ramos river forest 103 12 17:18 " //fails due 103
" 7 boyer hunter lowell 78 10 17:20 " //fails due 10
" 10 miguel tapia merrillville 98 11 17:32 //fails due 10
java regex string
No comments:
Post a Comment