简体   繁体   中英

url matching regex for php

I'm looking for a pattern that can match urls.

All of them will contain ".no" as there is only Norwegian domains input.

I think whats needed is this:

search for a space or linebreak before and after '.no', and the match will be a link.

Some examples of what it should match (all with text around it):

test.no
test.no/blablabla/
test.no/blablabla/test.html
test.no/blablabla/test.php
test.no/blablabla/test.htm

and this should then be replaced with

<a href="http://www.MATCH">MATCH</a>

anyone can figure this out?

应该这样做:

 $html = preg_replace("#\w+\.no[\w/.-]*#", '<a href="http://www.$0">$0</a>', $html);

检查John Gruber的正则表达式中的URL ,然后从那里继续。

我希望这足够严格:^ [\\ w \\ d-\\。\\\\] +。no。* $

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM