• 0

Having trouble with preg_replace_callback


Question

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

1 answer to this question

Recommended Posts

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.