Advertisement
Lajamerr_Mittesdine

URL Regex

Jun 4th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const QString urlRegExp = "^"
  2. // protocol identifier
  3. "(?:(?:https?|ftp)://)"
  4. // user:pass authentication
  5. "(?:\\S+(?::\\S*)?@)?"
  6. "(?:"
  7. // IP address exclusion
  8. // private & local networks
  9. "(?!(?:10|127)(?:\\.\\d{1,3}){3})"
  10. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})"
  11. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})"
  12. // IP address dotted notation octets
  13. // excludes loopback network 0.0.0.0
  14. // excludes reserved space >= 224.0.0.0
  15. // excludes network & broacast addresses
  16. // (first & last IP address of each class)
  17. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])"
  18. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}"
  19. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))"
  20. "|"
  21. // host name
  22. "(?:(?:[_a-z\\x{00a1}-\\x{ffff}0-9]-*)*[a-z\\x{00a1}-\\x{ffff0}-9]+)"
  23. // domain name
  24. "(?:\\.(?:[a-z\\x{00a1}-\\x{ffff0}-9]-*)*[a-z\\x{00a1}-\\x{ffff0}-9]+)*"
  25. // TLD identifier
  26. "(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,}))"
  27. "\\.?"
  28. ")"
  29. // port number
  30. "(?::\\d{2,5})?"
  31. // resource path
  32. "(?:[/?#]\\S*)?"
  33. "$";
  34.  
  35. static QRegularExpression linkRegex(urlRegExp, QRegularExpression::CaseInsensitiveOption);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement