Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This regexp (for php preg_replace) should match any URLs in text (beginning with protocol or by www.)
- # BUT only if they are not encapsulated by $ ($http://somewhere$ MUST NOT be matched).
- #
- # At first it is here splited to parts for easier reading
- # EDIT: Moved punctuation inside the outer parentheses
- #
- # ------- this is here for checking the $ sign at the beginning -------#
- (?<!\$)(?<!\$http:\/\/)(?<!\$https:\/\/)(?<!\$ftp:\/\/)(?<!\$ftps:\/\/)
- #-- detect protocol or www ----#
- ((((https?|ftps?):\/\/)|(www\.))
- # everything except spaces and so - I'm counting with IDN.
- # And strip punctuation from the end
- (\S+\.\S+)*[^\s,.?!])
- # check if the $ is not at the end
- (?!\$)
- # full regex without splitting
- (?<!\$)(?<!\$http:\/\/)(?<!\$https:\/\/)(?<!\$ftp:\/\/)(?<!\$ftps:\/\/)((((https?|ftps?):\/\/)|(www\.))(\S+\.\S+)*[^\s,.?!])(?!\$)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement