Pattern: URL

“URL” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match an internet address as you would enter into a web browser’s address bar. You can set the pattern to allow any URL, or to require specific schemes, ports, domains, file paths, parameters, etc.

This example shows how you can use the “URL” pattern to look for URLs. You can find this example as “Pattern: URL” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    regexmagic.com
    www.regexmagic.com
    http://regexmagic.com
    http://www.regexmagic.com
    http://www.regexmagic.com/
    http://www.regexmagic.com/index.html
    http://www.regexmagic.com/index.html?source=library
    support@regexmagic.com
  3. On the Match panel, click the Add First Field button to add field 1.
  4. In the “pattern to match field” drop-down list, select “URL”.



  5. Set the options for the URL pattern as shown in the screen shot.
  6. Set the “field validation mode” to “average”.
  7. On the Regex panel, select “C# (.NET 2.0–8.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \bhttps?://[.0-9a-z-]+\.[a-z]{2,63}(?::[0-9]{1,5})?(?:/[!$'()*+,.0-9_a-z-]+){0,9}(?:/[!$'()*+,.0-9_a-z-]*)?(?:\?[!$&'()*+,.0-9=_a-z-]*)?

    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

  8. The Samples panel now highlights the URLs our regex matches:
    regexmagic.com
    www.regexmagic.com
    http://regexmagic.com
    http://www.regexmagic.com
    http://www.regexmagic.com/
    http://www.regexmagic.com/index.html
    http://www.regexmagic.com/index.html?source=library
    support@regexmagic.com

Reference