Php 如何检查字符串仅包含a-z

Php 如何检查字符串仅包含a-z,php,regex,string,Php,Regex,String,我有一些字符串如下: $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

我有一些字符串如下:

$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
如您所见,我需要确定字符串是否为纯英语。我该怎么做?

假设“纯英语”=英语字母+空格:

^[a-zA-Z ]*$
  • [a-zA-Z]
    定义包含小写和大写字母+空格的字符集
  • *
    -重复任意次数
  • ^$
    -确保字符串从开始(
    ^
    )一直匹配到结束(
    $

什么是纯英语???@Dagon它只包含
a-z
字符和空格。你的意思是验证字符串只有基本ASCII字母和空格吗?@MichaelBerkowski完全正确。那么这应该是主题行仅供参考,我如何添加所有符号(
@
^
%
等)对于它?@Shafizadeh,您可以将它们添加到括号之间。但是,请小心-某些字符具有特殊含义。例如,不要将
^
放在括号的开头,因为这样它将具有否定的含义。