在文本上找到带正则表达式的网址(find url with regex on text)

编程入门 行业动态 更新时间:2024-10-25 15:28:06
文本上找到带正则表达式的网址(find url with regex on text)

有很多像这样的主题,但我不知道我尝试了多少错误,所以这是原始文本

onclick="NewWindow('http://google.com','name','800','600','yes');return false">

这是我的代码

$re1='(onclick)'; $re2='(=)'; $re3='(.)'; $re4='(NewWindow)'; $re5='(\\()'; $re6='(.)'; $re7='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))'; $c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches); print_r($matches);

任何人都可以帮助我使用正则表达式和PHP获取网址?

这段代码有什么问题?

问候

there are a lot of topics like this one but i don't know what the error i tried a lot so this is the original text

onclick="NewWindow('http://google.com','name','800','600','yes');return false">

this is my code

$re1='(onclick)'; $re2='(=)'; $re3='(.)'; $re4='(NewWindow)'; $re5='(\\()'; $re6='(.)'; $re7='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))'; $c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches); print_r($matches);

any one can help me to get the url using regular expression and php??

what is the wrong with this code?

Regards

最满意答案

preg_match("/NewWindow\('([^']*)'/",$txt, $matches);

matches [1]包含url

这是你需要的吗?

(编辑:放入代码块,因为括号没有转义为correclty

preg_match("/NewWindow\('([^']*)'/",$txt, $matches);

matches[1] contains the url

is it what you need ?

(edit: put in code block because a parenthesis was not escaped correclty

更多推荐

本文发布于:2023-08-01 19:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   网址   到带   正则表达式   text

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!