user1898765
user1898765

Reputation: 323

How to get an url in a string with regex

I'm trying to use a regex to get an url but i miss the end of the url here is an example of string containing an url

<div class=\"ExternalClassC7001553FFC442DD9B99547999723C7B\">http://bazar.flow.be/Knowledge/Legal/FR/Ina/Circul/Circul BB adm. 2014/circ_bb_p_2014_xxx.doc</div>

I've to get this in output:

http://bazar.flow.be/Knowledge/Legal/FR/Ina/Circul/Circul BB adm. 2014/circ_bb_p_2014_xxx.doc

For now, i use this regex that return me: "http://bazar.flow.be/Knowledge/Legal/FR/Ina/Circul/Circul"

@"((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\._~%]*)*"

thanks for a solution

Upvotes: 0

Views: 63

Answers (4)

vks
vks

Reputation: 67968

((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\._~%]*)*([^<]+)*

Try this.See demo.

http://regex101.com/r/hQ1rP0/83

Upvotes: 0

Toto
Toto

Reputation: 91375

Just add space in last character class, and you can simplify your regex to:

(?:(?:https?|ftp|file)\://|www\.)[A-Za-z0-9.-]+(?:/[\w?&=;+!'()*.~% -]*)*

Upvotes: 1

KittMedia
KittMedia

Reputation: 7466

Just add a backslash and a space at the end of your regex:

@"((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\._~%\ ]*)*"

Upvotes: 0

aelor
aelor

Reputation: 11116

include a space in between somewhere:

@"((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\. _~%]*)*"

                                                                               |
                                                                          added space here

Upvotes: 1

Related Questions