PHP:另一个我无法弄清楚的正则表达式

时间:2012-04-23 19:22:07

标签: php regex

我在PHP中使用2个正则表达式时遇到问题

1。剥离http(s)://和www。

https://www.google.be/search?sclient=psy-ab&q=regex&oq=regex
http://www.google.be/search?sclient=psy-ab&q=regex&oq=regex
https://google.be/search?sclient=psy-ab&q=regex&oq=regex
http://google.be/search?sclient=psy-ab&q=regex&oq=regex

=> google.be/search?sclient=psy-ab&q=regex&oq=regex

2。 3-30个字符,可能包含a-zA-Z0-9。-_ *但需要至少一个字母或数字

Valid: -_l*96d.*
Invalid: *-_.

我搜索了这么久没有任何结果所以请帮忙!

非常感谢!

2 个答案:

答案 0 :(得分:1)

第二个正则表达式如下:

'/^(?=[0-9a-zA-Z])[a-zA-Z0-9\-\*_\.]{3,30)$/'

答案 1 :(得分:1)

    preg_replace('/^(http|https):\/\/(www\.)?/i', '', $url)
相关问题