我有几个这样的字符串:
$str = 'this is a test 1';
$str = 'this is a test س';
$str = 'this is a test!';
$str = 'this is a test';
我想要这个输出:
false // there is this number: `1`
false // there is a Arabic character: س
false // there is a exclamation mark
true // that's pure English
如你所见,我需要确定一个字符串是纯英语还是不是。我怎么能这样做?
答案 0 :(得分:2)
假设“纯英语”=英文字母+空格:
^[a-zA-Z ]*$
[a-zA-Z ]
- 定义包含大写和小写字母+空格*
- 重复任意次数^$
- 确保字符串从开头(^
)到结尾($
)匹配