我正在尝试编写一个解释比赛结果的程序.但是为了做到这一点,我需要使用正则表达式来测试字符串是否与使用该String.matches(String regex)方法的特定模式匹配.使用此方法时,我希望返回一些字符串,而不是true返回false.
使用以下字符串作为正则表达式模式,一些字符串返回,true而其他字符串也false应该返回true:
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:.]+[ ]+"
Run Code Online (Sandbox Code Playgroud)
这些是true使用该string.matches(String regex)方法返回的一些字符串:
" 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 …Run Code Online (Sandbox Code Playgroud)