Ejemplo n.º 1
0
    /**
     * Initialize the regex for this instance.
     */
    public static function initializeRegex()
    {
        self::$regex = <<<END_OF_REGEX
(?xi)
(?:\\b|^)
(  # Capture 1: entire matched URL
  (
   (?:[a-z][\\w-+]{0,19})?:/{1,3}  # URL protocol and colon followed by 1-3
                                  # slashes, or just colon and slashes (://)
    |                             #  - or -
    (?<!\\.)www\\d{0,3}\\.           # "www.", "www1.", "www2." … "www999."
                                  # without a leading period
    |                             #  - or -
    [a-z0-9.\\-]+\\.[a-z]{2,4}/    # looks like domain name followed by a slash
  )
  (?:                           # One or more:
    [^\\s()<>\\[\\]]+                         # Run of non-space, non-()<>
    (?<![\\s`!()\\[\\]{};:\\'".,<>?«»“”‘’]{2}) # that is not followed by two or more
                                           # punct chars that indicate end-of-url
    |                                      #  - or -
    \\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)     # balanced parens, up to 2 levels
  )+
  (?:                           # End with:
    \\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)  # balanced parens, up to 2 levels
    |                                   #  - or -
    [^\\s`!()\\[\\]{};:\\'".,<>?«»“”‘’]     # not a space or one of these punct
                                        # chars
  )
)
END_OF_REGEX;
    }