Regex to deny sentence
Moderator: General Moderators
Regex to deny sentence
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?
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?
Re: Regex to deny sentence
So... if the href you matched was that one you don't want, skip it.
Re: Regex to deny sentence
exactly.requinix wrote:So... if the href you matched was that one you don't want, skip it.
Re: Regex to deny sentence
So what's the question? Or what code do you have?
Re: Regex to deny sentence
I have this code but it matchs any href without distiction.requinix wrote:So what's the question? Or what code do you have?
<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.
Re: Regex to deny sentence
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.
There may be a perfectly legitimate reason why that won't work for your circumstance but I haven't heard it yet.
Code: Select all
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
}
}Re: Regex to deny sentence
I'd like to do this in a single regex line. Not using any kind of iteration.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.There may be a perfectly legitimate reason why that won't work for your circumstance but I haven't heard it yet.Code: Select all
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 } }
Is that possible?
Re: Regex to deny sentence
Yeah, but aren't you going to need iteration somewhere? What are you doing with these hrefs?
Remember to escape characters like . and /.
Code: Select all
<link rel="image_src" href="(?!url you don't want)([^\"]+)"Re: Regex to deny sentence
Not really, I just need this to extract a image from a web page.requinix wrote:Yeah, but aren't you going to need iteration somewhere? What are you doing with these hrefs?
Remember to escape characters like . and /.Code: Select all
<link rel="image_src" href="(?!url you don't want)([^\"]+)"
Is this right? It won't recognize some of the characteres.
Code: Select all
<link rel="image_src" href="(?!http://s1.trrsf.com.br/atm/3/core/_img/terra-logo-white-bg-v2.jpg)([^\"]+)"Re: Regex to deny sentence
Where is offset 96?
Also,
Also,
requinix wrote:Remember to escape characters like . and /.
Re: Regex to deny sentence
Actually It must be compatible cause the application I'm using it is based on TestRExp (http:// regexpstudio. com/RegExpStudio.html).
Thanks anyway.
Thanks anyway.