Link to home
Start Free TrialLog in
Avatar of robrodp
robrodpFlag for Mexico

asked on

Reg Exp to extract Url from string asp

I need the code to extract  Url from string asp Reg Exp
Avatar of Big Monty
Big Monty
Flag of United States of America image

can you give us an example of what you're looking to do?
Avatar of robrodp

ASKER

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://
try the following:

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

ASKER

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
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

Avatar of robrodp

ASKER

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?
Avatar of robrodp

ASKER

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?
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?
Avatar of robrodp

ASKER

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
%>
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of robrodp

ASKER

Thx 1,000,000