• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Having trouble with preg_replace_callback

Question

Danielx64    608

Hello all,

 

I'm trying to write a

preg_replace_callback(); function that would find

[attachment=0]14547801_194886730949087_6033257422456356864_n.jpg[/attachment] 


 

Right now I have tried using

 

#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#

and basically nuke it.

 

but it doesn't seems to be working. My current code looks like this:

 

$resume_text = preg_replace_callback('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#', "callback", $resume_text);

function callback($match)

{
    return $match;
}

 

Could someone please tell me where I am going wrong?

 

https://regex101.com/r/LUhkmp/1

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
jamieakers    192

Something like this?

(?<=(\[attachment=[0-9]\]))(.*)(?=\[\/attachment)

https://regex101.com/r/LUhkmp/3

 

FWIW I find regexr much more user-friendly.  Same thing on their site: http://regexr.com/v1?394tp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.