可以使用以下正则表达式:

/(https?:\/\/[\w\.\/]+)/

解释:

  • https?:\/\/:匹配以 http://https:// 开头的字符串。
  • [\w\.\/]+:匹配由字母、数字、点和斜杠组成的字符串,可以匹配到路径和文件名。

PHP代码示例:

$url = 'http://www.example.com/path/to/file.php';
preg_match('/(https?:\/\/[\w\.\/]+)/', $url, $matches);
echo $matches[1]; // 输出 http://www.example.com/path/to/
httpwwwexamplecompathtofilephp 使用php 正则匹配得到httpwwwexamplecompathto

原文地址: https://www.cveoy.top/t/topic/fJjs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录