Hello, I got a JavaScript URL Validation Regex, since I'm not used-to with Regex I need help converting it into PHP regex. Here is a JavaScript Regex I need this particular regex in PHP Thanks in advance
if (preg_match('|^https?://(www\d{0,4}\.)?([-_A-Za-z0-9]+\.)?[-_.A-Za-z0-9]+(\.[A-Za-z]{2,6})([-0-9a-zA-Z_%&?~/.=]*)$|', $url)) echo "yes\n"; else echo "no\n"; PHP:
Underground-stockholm, Thanks for your contribution but I couldn't find the match with the Regex you've provided to me.. I tested the following url and I doubt if the javascript regex I've does this for me.. $url="http://www.facebook.com/profile.php?id=66665555#!/home.php?sk=group_66665555&ap=1"; Code (markup): I'm waiting for the improved regex thanks
there is no best regexp to match urls as modern age design rules changes heavily.You will need to analayse specific situation and see whats best for you.As usually there is a single ? in urls but as your urls as more than one so this regex wont work..there can be also troubles in matching relative and absolute urls..So first find what you need and code accordingly. Hope that helps
This wouldn't work for international domain names, or any addresses that have non english characters. Just a note.