0

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

4 Answers 4

1

include a space in between somewhere:

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

                                                                               |
                                                                          added space here
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

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

Try this.See demo.

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

2 Comments

it won't work here regex101.com/r/hQ1rP0/82 (\s\S+)* will consume all the following characters.
adding this [^<>]* after the last also works. A simple solution is adding space inside the last character class..
0

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\?\&\=;\+!'\(\)\*\-\._~%\ ]*)*"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.