Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 理解preg_匹配公式_Php_Regex_Preg Match - Fatal编程技术网

Php 理解preg_匹配公式

Php 理解preg_匹配公式,php,regex,preg-match,Php,Regex,Preg Match,不管怎样,我的东西是按照下面的思路工作的,但我真的不明白 if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Desktop/test/b '$test'"),$matches)) { $x = (int) $matches[1][0]; //optionally cast to int

不管怎样,我的东西是按照下面的思路工作的,但我真的不明白

if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Desktop/test/b '$test'"),$matches))
                {
                        $x = (int) $matches[1][0]; //optionally cast to int
                        $y = (int) $matches[1][1];
                        $pcount= round((100*$x)/($x+$y),2);
                        $ncount= round((100*$y)/($x+$y),2);
                }
b
是可执行文件,它给出的结果类似于
x=10
y=20

有人能解释一下if()中的任何内容吗:
/[^=]*=([^;@]*)/
将所有
…=
内容收集到$matches数组中

  • [^=]
    表示除=
  • [^;@]
    表示除以下字符以外的任何字符:;及@
  • ()
    表示将其收集到$matches中
$pcount/$ncount从显示其比率的值中提取百分比。

模式详细信息:

[^=]*       # is a negated character class that means "all characters except ="
            # * is quantifier that means zero or more times
            # note that it seems more logical to replace it with + 
            # that means 1 or more times

=           # literal =

(           # open the capturing group 1
  [^;@]*    # all characters except ";" and "@", zero or more times
            # (same notice) 
)           # close the capturing group 1

什么不清楚?阅读PHP手册页面;阅读Regex tuturial——有很多(在谷歌中输入Regex教程),我发现这些是调查Regex的有用工具,@WayneC:谢谢,伙计!我希望你是在净化
$test
谁知道当有人做坏事时会发生什么