Click here to Skip to main content
15,867,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anyone got any ideas how to match links from such string:
C#
"http://www.youtube.com/Vid56xtghhttp://vimeo.com/channel/id=14498http://rapigator.net/file/345gtrG/mike_goes_mad.avi"


Basically this string contains 3 links merged together. I need to separate it out somehow into 3 distinct links. Any way to do that with regular expression?

Thanks!

What I have tried:

Tried playing with regular expressions but without any luck. Not sure how to stop it when another "http(s)?://(www\.)?" block is reached...
Posted
Updated 2-May-16 5:14am
v2
Comments
Patrice T 2-May-16 11:19am    
By the hell, how did you end up with something as stupid as the 3 links in a single string ?
MK-Gii 3-May-16 2:30am    
Simple - some sites have reference links in placed in comments and when I get the content - everything is mixed.

You can try this
http:(?:(?!http:).)*

It will match from http: up to the next occurence, but not including it.
The result of your sample string will be 3 separate matches.

[UPDATE]
Forgot the https variant:
http(?:s)?:(?:(?!http(?:s)?:).)*
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 2-May-16 10:52am    
5ed.
This also boils down to our last comments. First response could be: what the hell is that input data with "merged links"? Should the purpose of programming be compensation of someone's idiocy? Maybe elimination of idiocy could be a bit more productive? :-)
—SA
George Jonsson 2-May-16 10:56am    
Very true. Bad (or strange) input data seems to be very common.
Patrice T 2-May-16 11:18am    
5ed too
George Jonsson 2-May-16 11:26am    
Thanks :-)
MK-Gii 10-May-16 3:40am    
I used this:
http(s)?://((?!(http)).)*
See solution 1 for a working solution.

This site can help to see if a regex is doing what you expect.
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]

I guess you will have to read regex documentation to understand advanced usages.
perlre - perldoc.perl.org[^]

By the hell, how did you end with something as stupid as the 3 links in a single string ?
 
Share this answer
 
Comments
George Jonsson 2-May-16 11:27am    
Valid question.
Good point with the Regex tools too.
Patrice T 2-May-16 11:31am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900