Reg Exp to extract Url from string asp

I need the code to extract  Url from string asp Reg Exp
robrodpProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
can you give us an example of what you're looking to do?
0
robrodpProgrammerAuthor Commented:
I have a long string (and I have to do it for many)

I need a regular expression that will extract the url following url=

Say for example

<html>
<head>
    <title>Omgili Redirection</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta http-equiv="refresh" content="5; url=https://www.elsoldemexico.com.mx/mexico/619673-advierten-a-empresas-mexicanas-por-costo-social-si-van-por-el-muro" />
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                m=s.get

I need to extract the url:

https://www.elsoldemexico.com.mx/mexico/619673-advierten-a-empresas-mexicanas-por-costo-social-si-van-por-el-muro

with http:// or https://
0
Big MontyWeb Ninja at largeCommented:
try the following:

"http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

robrodpProgrammerAuthor Commented:
Hi thx

I have the expression what I need is a working asp code:
Set regEx = New RegExp
    regEx.Pattern = "http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
    regEx.Global = true
    Set RegExResults = regEx.Execute(strTarget)
    Set regEx = Nothing

Set arrResults = RegExResults(pagina)

Open in new window


I need to extract the exact url from as´p
0
Big MontyWeb Ninja at largeCommented:
clarifying what exactly you need will usually help in the long run...

function getURL( str ) 
    Set regEx = New RegExp
    regEx.Pattern = "http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
    regEx.Global = true
    Set RegExResults = regEx.Execute( str )
    Set regEx = Nothing

   getURL = RegExResults
end function

url = getURL( strToCheck )

Open in new window

0
robrodpProgrammerAuthor Commented:
Thx

I am getting this:

<font face="Arial" size=2>Wrong number of arguments or invalid property assignment</font>
<p>
<font face="Arial" size=2>/xstandard/httpreg.asp</font><font face="Arial" size=2>, line 23</font>

Any ideas?
0
robrodpProgrammerAuthor Commented:
This is the string where the url is and I want to extract the url.

<html>
<head>
    <title>Omgili Redirection</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta http-equiv="refresh" content="5; url=https://www.elsoldemexico.com.mx/mexico/619673-advierten-a-empresas-mexicanas-por-costo-social-si-van-por-el-muro" />
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                m=s.get

What am I doing wrong?
0
Big MontyWeb Ninja at largeCommented:
can you post your full code, including a string to test on? something that I can throw in a page (so code without any dependencies) for testing?
0
robrodpProgrammerAuthor Commented:
pagina is the string from which http://www.lasalud.mx/permalink/18633.htm is to be extracted
<%
pagina="<html>'<head>'    <title>Omgili Redirection</title>'    <meta http-equiv='content-type' content='text/html;charset=utf-8'>'    <meta http-equiv='' content='5; url=http://www.lasalud.mx/permalink/18633.html' />' "


Set regEx = New RegExp
    regEx.Pattern = "/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/"
    regEx.Global = true
    Set RegExResults = regEx.Execute(pagina)
    Set regEx = Nothing

Set arrResults = RegExResults

response.write arrResults
%>
0
Big MontyWeb Ninja at largeCommented:
give this a shot, as it works for me. it IS leaving a trailing single quote, not sure why, as it's listed in the pattern, but you should be able to figure that part out :)

<%
pagina="<html>'<head>'    <title>Omgili Redirection</title>'    <meta http-equiv='content-type' content='text/html;charset=utf-8'>'    <meta http-equiv='' content='5; url=http://www.lasalud.mx/permalink/18633.html' />' "
    
Function RegExResults(strTarget)

    Set regEx = New RegExp
    regEx.Pattern = "http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
    regEx.Global = true
    Set RegExResults = regEx.Execute(strTarget)
    Set regEx = Nothing

End Function

'Pass the original string and pattern into the function and get a collection object back'
Set arrResults = RegExResults(pagina)

'In your pattern the answer is the first group, so all you need is'
For each result in arrResults
    Response.Write(result.Value)
Next

Set arrResults = Nothing
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robrodpProgrammerAuthor Commented:
Thx 1,000,000
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.