Public
Authored by Torbjørn Viem Ness

RE example for URL matching

Work in progress on regular expressions for matching URLs

URL regex without query string part (works in JS, not PCRE - according to regexr):

(https?|ftp):\/\/[-\w]+(\.[-\w]+)*(\.[\w]{2,})(\/[-\/\w]*)*

Query string regex (works both in JS and PCRE):

(\?(([-\w]+)(=(([-\w]+)(\&(([-\w]+)(=([-\w]+)*))?)*)?)?)?)

A full example (JS compatible) could look like this:

/(https?|ftp):\/\/[-\w]+(\.[-\w]+)*(\.[\w]{2,})(\/[-\/\w]*)*(\?(([-\w]+)(=(([-\w]+)(\&(([-\w]+)(=([-\w]+)*))?)*)?)?)?)?/i
Edited
39 Bytes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment