Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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中的exp_Php_Regex - Fatal编程技术网

帮我做这个注册。PHP中的exp

帮我做这个注册。PHP中的exp,php,regex,Php,Regex,我不知道正则表达式,我在这里要了一个: 获取直到第一个括号/冒号或第一个括号内的第一个单词的任何内容。答案是: preg_match('/(?:^[^(:]+|(?<=^\\()[^\\s)]+)/', $var, $match); 谢谢 这是一个简单的改变: preg_match('/(?:^[^(:“]+|)(?如果你对正则表达式一无所知,也许你最好编写一个小函数,用strstr()和substr()等实现你想要的功能。正则表达式只会变得更复杂,甚至比你现在需要的更难维护。 $var

我不知道正则表达式,我在这里要了一个: 获取直到第一个括号/冒号或第一个括号内的第一个单词的任何内容。答案是:

preg_match('/(?:^[^(:]+|(?<=^\\()[^\\s)]+)/', $var, $match);
谢谢

这是一个简单的改变:


preg_match('/(?:^[^(:“]+|)(?如果你对正则表达式一无所知,也许你最好编写一个小函数,用
strstr()
substr()
等实现你想要的功能。正则表达式只会变得更复杂,甚至比你现在需要的更难维护。
$var = 'story "The Town in Hell"s Backyard';     // I get this: $match = 'story';
$var = "screenplay (based on)";             // I get this: $match = 'screenplay';
$var = "(play)";                                  // I get this: $match = 'play';
$var = "original screen";              // I get this: $match = 'original screen';