Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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,我正在使用php,需要找到下面定义的通配符字符串。然后我需要在通配符值的末尾追加一个字符串 值为“awn.漏斗.Widget.createForm”(“awn.co.uk”,“--wildcard--here--”) 以下是我尝试过的: if (preg_match('/awn.Funnel.Widget.createForm("awn.co.uk",[_a-zA-Z]+/', $competition_code, $matches)) { print_r ($matches); } 但它给了

我正在使用php,需要找到下面定义的通配符字符串。然后我需要在通配符值的末尾追加一个字符串

值为“awn.漏斗.Widget.createForm”(“awn.co.uk”,“--wildcard--here--”)

以下是我尝试过的:

if (preg_match('/awn.Funnel.Widget.createForm("awn.co.uk",[_a-zA-Z]+/', $competition_code, $matches)) { print_r ($matches); }
但它给了我:

Warning: preg_match(): Compilation failed: missing ) at offset 52

preg_匹配的第一个参数:

'/awn.Funnel.Widget.createForm("awn.co.uk",[_a-zA-Z]+/'
是正则表达式模式。因此,字符“
”被解释为捕获组的开始。因为这不是您想要的,所以您需要转义参数:

'/awn.Funnel.Widget.createForm\("awn.co.uk",[_a-zA-Z]+/'
您还应该转义“
”,因为如果不转义,这些字符将被解释为任何字符,而不是句点。

您的正则表达式:

'/awn.Funnel.Widget.createForm("awn.co.uk",[_a-zA-Z]+/'
应改写为:

'/awn\.Funnel\.Widget\.createForm\("awn\.co\.uk",[_a-zA-Z]+/'
或者更好地使用

$regex = '/' . preg_quote('awn.Funnel.Widget.createForm("awn.co.uk', '/') 
         . '[_a-zA-Z]+/';

请提供具体的例子。那么就这样做吧!你试过什么,什么不起作用?