PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 27, 2014 6:31 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Regex to deny sentence
PostPosted: Thu Sep 06, 2012 10:12 am 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
Hi guys,

I need to find any URL (in red) inside this sentence:

<link rel="image_src" href="any URL"

But it cannot be at any circunstante this one:

<link rel="image_src" href="http://s1. trrsf. com .br/atm/3/core/_img/terra-logo-white-bg-v2 .jpg"

I'm using this regex but it finds everything:

<link rel="image_src" href="([^\"]+)"

Any advice?


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 12:23 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5659
Location: WA, USA
So... if the href you matched was that one you don't want, skip it.


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 12:32 pm 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
requinix wrote:
So... if the href you matched was that one you don't want, skip it.

exactly.


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 12:41 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5659
Location: WA, USA
So what's the question? Or what code do you have?


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 12:47 pm 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
requinix wrote:
So what's the question? Or what code do you have?


I have this code but it matchs any href without distiction.
<link rel="image_src" href="([^\"]+)"

it should not match the URL: http://s1. trrsf. com .br/atm/3/core/_img/terra-logo-white-bg-v2 .jpg.


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 2:15 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5659
Location: WA, USA
And I'm telling you the easiest option: let it match whatever it wants to match and make the rest of the code skip the match if you don't want it.
Code:
for each $href in all the hrefs the regex matched {
    if $href is something you don't want to include {
        continue looking at the next href
    } otherwise {
        do whatever
    }
}

There may be a perfectly legitimate reason why that won't work for your circumstance but I haven't heard it yet.


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 2:17 pm 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
requinix wrote:
And I'm telling you the easiest option: let it match whatever it wants to match and make the rest of the code skip the match if you don't want it.
Code:
for each $href in all the hrefs the regex matched {
    if $href is something you don't want to include {
        continue looking at the next href
    } otherwise {
        do whatever
    }
}

There may be a perfectly legitimate reason why that won't work for your circumstance but I haven't heard it yet.

I'd like to do this in a single regex line. Not using any kind of iteration.
Is that possible?


Top
 Profile  
 
PostPosted: Thu Sep 06, 2012 3:03 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5659
Location: WA, USA
Yeah, but aren't you going to need iteration somewhere? What are you doing with these hrefs?

Code:
<link rel="image_src" href="(?!url you don't want)([^\"]+)"

Remember to escape characters like . and /.


Top
 Profile  
 
PostPosted: Mon Sep 10, 2012 7:13 am 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
requinix wrote:
Yeah, but aren't you going to need iteration somewhere? What are you doing with these hrefs?

Code:
<link rel="image_src" href="(?!url you don't want)([^\"]+)"

Remember to escape characters like . and /.


Not really, I just need this to extract a image from a web page.
Is this right? It won't recognize some of the characteres.
Syntax: [ Download ] [ Hide ]
<link rel="image_src" href="(?!http://s1.trrsf.com.br/atm/3/core/_img/terra-logo-white-bg-v2.jpg)([^\"]+)"


I'm using Testrexp to test it. This is the error: "TRegExpr(comp): Urecongnized Modifier (pos 96)"


Top
 Profile  
 
PostPosted: Mon Sep 10, 2012 1:54 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 5659
Location: WA, USA
Where is offset 96?

Also,
requinix wrote:
Remember to escape characters like . and /.


Top
 Profile  
 
PostPosted: Mon Sep 10, 2012 3:18 pm 
Offline
Forum Newbie

Joined: Thu Sep 06, 2012 10:08 am
Posts: 6
Actually It must be compatible cause the application I'm using it is based on TestRExp (http:// regexpstudio. com/RegExpStudio.html).
Thanks anyway.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group