我有以下示例文件和正则表达式。
testing.txt
public function actionIndex()
{
$model=new User('search');
$model->unsetAttributes(); // clear any default values
$model->user_role = 2;// for student role
if(isset($_GET['User']))
$model->attributes=$_GET['User'];
$this->render('index',array(
'model'=>$model,
));
}
我使用egrep的正则表达式
testing aa
a bc de
e aa
ba Z
testing bb
testing ac
上述正则表达式试图在一行中找到连续的空格。 但是,返回的结果是空的。
下面的规范表达式适用于1个或多个空格。然而,这不是我想要的。
egrep '[ ]{2,}' testing.txt
答案 0 :(得分:0)
如果您的系统已旧,this help reference可能正在描述此问题:
传统的egrep不支持
{
元字符,而有些egrep实现支持\{
,因此可移植脚本应避免在egrep模式中{
使用[{]
匹配文字{
。
这意味着,如果grep '[ ]\{2,\}' testing.txt
不起作用 - 最好使用Perl或GNU grep来实现你想要的效果。
此外,egrep '[ ][ ]+' testing.txt
似乎只是在目前的情况下解决方法,并且不会扩展,但它肯定会帮助你暂时。