Last active
October 21, 2019 17:10
-
-
Save dizzersee/8457b22a28330f724409ff9e36ff4de6 to your computer and use it in GitHub Desktop.
Regex that matches a URL until a specific sequence appears
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https\:\/\/(www.)?(domain.com\/?)\S*?(?=((\<br)|(\(\()| |$)) | |
Test https://www.regextester.com/ | |
======== REGEX ======== | |
\S*? | |
- ? is Lazy operator: Match as few characters as possible | |
(?=((\<br)|(\(\()| |$)) | |
- Positive lookahead ?= matches a group after the main expression without including it in the result. | |
- 4 Groups here: <br, ((, space, $ | |
======== EXAMPLES ======== | |
- Match www/non-www URL until a "<br", "((", or a space | |
Lorem ipsum https://www.domain.com((lorem | |
- matches https://www.domain.com | |
Lorem ipsum https://www.domain.com/((ebig | |
- matches https://www.domain.com/ | |
Lorem ipsum https://www.domain.com/lorem((lorem | |
- matches https://www.domain.com/lorem | |
Lorem ipsum https://www.domain.com/lorem((lorem | |
- matches https://www.domain.com/lorem | |
Lorem ipsum https://www.domain.com<br | |
- matches https://www.domain.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment