preg_match()未知修饰符'['帮助

更新时间:2022-06-22 22:47:59

尝试以下操作:

<?php
  $str = "http://www.***.com/ytscreeningroom?v=NRHVzbJVx8I";
  $pattern = '#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&\n]+|(?<=v=)[^&\n]+#';
  preg_match($pattern, $str, $matches); 
  print_r($matches);
?>

请注意,我在这里使用#作为分隔符只是因为上面的正则表达式包含正斜杠,而转义它们会使表达式更难以阅读.这样可以清理几个像素.

Note, I'm using # as a delimiter here simply because the regular expression above contains forward slashes and escaping them makes the expression more difficult to read. This cleans it up by just a few pixels.

相关阅读

技术问答最新文章