Reputation: 37
I need to clean all links in long string. Eg:
http://www.example.com
http://example.com
www.example.net
youtube.com/user/123456
facebook.com/example
sub.domain.com
I want remove all link and choosing this code but not working all links.
(?>http?://|ww\w\.).+?(?=\s)
How to fix this problem?
Thank you!
Upvotes: 2
Views: 8426
Reputation: 11
Same as Matthew wrote but would get rid of that space in the last bracket - then it won't catch the text after the link. So it would be like this:
(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)
PS. Sorry Matthew - I cannot yet comment. But I've created the account to thank you for your reply - it solved my issue as well :)
Upvotes: 1
Reputation: 3442
Regular Expression:
(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)
Example Execution: http://regexr.com?38bj4
Reference: http://code.tutsplus.com/tutorials/8-regular-expressions-you-should-know--net-6149
Upvotes: 3