我想确定一个字符串是否只包含两个单词,它们之间有一个空格字符.第一个单词应该只包含字母数字字符.第二个应该只包括数字.一个例子是:asd 15
我想用String.matches.我该怎么做或者我应该使用哪个正则表达式?
提前致谢.
你寻找像这样的东西:
String regex = "^[A-Za-z]+ [0-9]+$";
Run Code Online (Sandbox Code Playgroud)
说明:
^ the beginning of the string (nothing before the next token)
[A-Za-z]+ at least one, but maybe more alphabetic chars (case insensitive)
a single space (hard to see :) )
[0-9]+ at least one, but maybe more digits
$ end of the string (nothing after the digits)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10602 次 |
| 最近记录: |