Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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中匹配格式变量=[[word]]中的word的简单正则表达式_Php_Regex - Fatal编程技术网

在php中匹配格式变量=[[word]]中的word的简单正则表达式

在php中匹配格式变量=[[word]]中的word的简单正则表达式,php,regex,Php,Regex,我必须用格式示例搜索大量文本 traded_as = {{NASDAQ|GOOG}}<br>{{NASDAQ|GOOGL}}<br>[[Company name]]<br>. 试试下面的方法 preg_match('/\[\[([^]]*)\]]/', $txt, $match); echo $match[1]; 你还应该添加你已经尝试过的正则表达式。你可以先在类似的网站上尝试正则表达式。 preg_match('/\[\[([^]]*)\]]/', $t

我必须用格式示例搜索大量文本

traded_as = {{NASDAQ|GOOG}}<br>{{NASDAQ|GOOGL}}<br>[[Company name]]<br>.
试试下面的方法

preg_match('/\[\[([^]]*)\]]/', $txt, $match);
echo $match[1];

你还应该添加你已经尝试过的正则表达式。你可以先在类似的网站上尝试正则表达式。
preg_match('/\[\[([^]]*)\]]/', $txt, $match);
echo $match[1];
<?php
    $string = "{{NASDAQ|GOOG}}<br>{{NASDAQ|GOOGL}}<br>[[Company name]]<br>";
    preg_match('/\[\[(.*?)\]\]/', $string, $regs);
        $result = $regs[1];
        echo $result;
        //Company name
?>
Match the character “[” literally «\[»
Match the character “[” literally «\[»
Match the regular expression below and capture its match into backreference number 1 «(.*?)»
   Match any single character that is not a line break character «.*?»
      Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “]” literally «\]»
Match the character “]” literally «\]»