Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 这个正则表达式是什么意思?_Php_Regex - Fatal编程技术网

Php 这个正则表达式是什么意思?

Php 这个正则表达式是什么意思?,php,regex,Php,Regex,有人能告诉我它到底想匹配什么吗 $exp = '/[\s]+col[\s]*=[\s]*"([^"]*)"/si'; 它似乎在匹配col=“some value”,同时非常宽容等号周围的空格,不区分大小写,并且不管值是否为空 另一方面,很奇怪s修饰符在那里做什么,因为那里没有元字符。如果添加/x修饰符,可以编写带注释的正则表达式。因此,这里有一个冗长且有文档记录的版本(对于复杂的版本总是建议的): 你有时也会看到我认为其他人已经给出了一个很好的答案。顺便说一句,如果这不是你的问题 解析标记,然

有人能告诉我它到底想匹配什么吗

$exp = '/[\s]+col[\s]*=[\s]*"([^"]*)"/si';

它似乎在匹配
col=“some value”
,同时非常宽容等号周围的空格,不区分大小写,并且不管值是否为空


另一方面,很奇怪
s
修饰符在那里做什么,因为那里没有
元字符。

如果添加
/x
修饰符,可以编写带注释的正则表达式。因此,这里有一个冗长且有文档记录的版本(对于复杂的版本总是建议的):


你有时也会看到我认为其他人已经给出了一个很好的答案。顺便说一句,如果这不是你的问题 解析标记,然后您可以使用以下内容增强字符串端的功能 这:

\s+col\s*=\s*”(((?:\\.[^\\\“]+)*)”

Perl’ish应该是:

use strict;
use warnings;

my $regex = qr/

    \s+ col \s* = \s* "( (?: \\. | [^\\"]+ )* )"

/sx;

my $string = q(
 col  =  " this'' is \" a test\s,
           of the emergency broadcast system,
           alright .\". cool."
);

if ( $string =~ /$regex/ )
{
     print "Passed  val =\n $1\n";

}
__END__

Passed  val =
  this'' is \" a test\s,
           of the emergency broadcast system,
           alright .\". cool.

@Abdullah Jibaly:是的,可能只是一个非常宽容的正则表达式。@Abdullah这样匹配'COL=”“',或者可能是因为HTML不区分大小写。@mario:我就是这么想的。哪个元素有
COL
属性?我知道textarea有
cols
(复数)…它可以压缩为
/\scol\s*=\s*([^]*)”/i
这意味着有些人不太了解正则表达式。对于windows平台上的正则表达式,应用程序“RegexBuddy”对于理解和构造模式非常有用。@Scuzzy:我肯定它也可以在Wine上运行。但无论如何,有很多免费的替代品:可爱,正则表达式修饰符拼写
six
。很好的多行语法…尽管有时你会在属性中找到,大多数浏览器都会使用它。
use strict;
use warnings;

my $regex = qr/

    \s+ col \s* = \s* "( (?: \\. | [^\\"]+ )* )"

/sx;

my $string = q(
 col  =  " this'' is \" a test\s,
           of the emergency broadcast system,
           alright .\". cool."
);

if ( $string =~ /$regex/ )
{
     print "Passed  val =\n $1\n";

}
__END__

Passed  val =
  this'' is \" a test\s,
           of the emergency broadcast system,
           alright .\". cool.