Jump to content

Regex for grabbing everything but a variable.


jamesmiller

Recommended Posts

Hey guys, basically i need a regex to reterieve part of a string but exclude strings that end with a certain variable. I was wondering how this could be achieved so far i have:

preg_match('!/load/!is',$href) 

 

but it retrieves strings that have /load/files/wjnjsnws/ which i dont want i just want the /load/

 

thank you guys

Link to comment
Share on other sites

ok the content is

 

<a href="/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481/files/gregr" rel="nofollow" onclick="return listfiles(this,750,50,'2px solid',0,0,'img4358813f031ffa01ba1164c238696eb8e24079b24481');">
	<img name="img4358813f031ffa01ba1164c238696eb8e24079b24481" src="/images/expand.gif" alt="File Listing" border="0"></a> 
	<a href="/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481" class="BlckUnd"><font color="#CC0000">gg</font> <

 

i want to get one of these which is the /load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481

 

thank you

Link to comment
Share on other sites

There is no way that the RegEx i provided would ever match '/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481/files/etc' in it's entirety.

 

It will, however, extract '/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481' out of '/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481/files/etc'.

 

Is this not a good solution? Perhaps you should give me detailed examples where my expression returns false positive.

 

Try this. I can only guarantee it will work with the sample data you've provided.

%(/load/gg/(?:[^/"]++))"%i

Link to comment
Share on other sites

O RLY? This is going beyond my patience levels.

 

<?php

$string = <<<HEREDOC
<a href="/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481/files/gregr" rel="nofollow" onclick="return listfiles(this,750,50,'2px solid',0,0,'img4358813f031ffa01ba1164c238696eb8e24079b24481');">
	<img name="img4358813f031ffa01ba1164c238696eb8e24079b24481" src="/images/expand.gif" alt="File Listing" border="0"></a> 
	<a href="/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481" class="BlckUnd"><font color="#CC0000">gg</font> <;
HEREDOC;

$expr = '%/load/gg/(?:[^/"]++)%i';

preg_match( $expr, $string, $match );

print_r( $match );

?>

 

Output

Array
(
    [0] => /load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481
)

 

Until you start APPLYING the help you're getting, I'm done with this thread.

Link to comment
Share on other sites

I don't understand how my snippet above is producing the correct results while yours isn't.

 

Have you copied and pasted my code, and tried it on your system?

 

Perhaps you have given us bad data to try and build a RegEx off of. A complete set of data may help with this.

 

Again, though, the expression I provided should NEVER match '/load/gg/4358813f031ffa01ba1164c238696eb8e24079b24481/files/gregr'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.