I want to combine 
[/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/ from How to validate domain name using regex? (this works only for single words not text)] 
 and 
 [/(\b(((https?|ftp|file):\/\/)|(ww.\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig from Detect URLs in text with JavaScript (this works for text)] 
 into a single regex. 
 
 
How can this be achieved?
            Asked
            
        
        
            Active
            
        
            Viewed 98 times
        
    0
            
            
        - 
                    Possible duplicate of [Detect URLs in text with JavaScript](http://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript) – Mar 20 '16 at 00:45
- 
                    1@noob - I have already referenced the link in my original question – Yaan Mar 20 '16 at 00:46
- 
                    How do you want the answer to differ from the second regexp you mentioned? – LarsH Mar 20 '16 at 02:13
- 
                    @LarsH The second regex does not match `lkmo.co.pl` (or `google.com`), it does match `http://lkmo.co.pl` (or `https://google.com`). Would like to add this aspect to the second regex – Yaan Mar 20 '16 at 02:40
- 
                    So, by "combine" you mean that you want a regex that matches everything that the first one matches, as well as everything that the second one matches? Then you want `(A)|(B)`, where A and B are the two regexes. Alternatively, you could put `?` before the first `[` in the second regex: `/(\b(((https?|ftp|file):\/\/)|(ww.\.))?[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig` – LarsH Mar 20 '16 at 02:44
- 
                    @LarsH - thanks for the comment, it worked :) – Yaan Mar 20 '16 at 07:01
 
    