I'm using a custom program that parses a script based on strings between ~'s. This is what I need to do:

Take this string for example:

$string = "~Blah, blah, blah.  j123, blah, blah.~

j532

~Blah, j392.~";

Now I need to preg_replace that string so it becomes this:

$string = "~Blah, blah, blah.  123, blah, blah.~

j532

~Blah, 392.~";

So, basically I need to replace any numerical reference that is prepended by a j only if it's between two tildes.

I've tried numerous things, including look ahead and behind assertions, but I can't get it to work.

Thanks for any help.

    Ah, I should wait before I post things like this. 🙂

    Figured it out.

    Here's the solution incase anyone actually cares:

    $string = "~Blah, blah, blah.  j123, blah, blah.~ 
    
    j532 
    
    ~Blah, j392.~";
    
    $string = preg_replace("#(~.*?)j(\d{1,3})(.*?~)#","\\\\1\\\\2\\\\3",$string);
    
      Write a Reply...