2

I got the following string:

last_name, first_name
bjorge, philip
kardashian, [kghim]
mer#$##Code:menu:51587daa7030e##$#cury some more
data #$##Code:menu:515r4387daa7dsf030e##$#, freddie

im trying to replace the Codes in the middle with the function: 'codeParser' the regex is:

$PC_File = preg_replace_callback("(?=\#\$\#\#).*?(?<=\#\#\$\#)", 'codeParser', $PC_File);

but getting this error:

PHP Warning:  preg_replace_callback() : Unknown modifier '.'
Mike
  • 680
  • 13
  • 39
  • 2
    @Ashish I'm glad that's only a comment and not an answer :P – AD7six Apr 01 '13 at 15:56
  • Now that the delimiter problem has been solved, let's talk about those lookarounds. `'/#\$##(.*?)##\$#/'` matches the same things your regex does, but much more efficiently. The capturing group allows you to access the `Code` value directly (via `$matches[1]`), so you don't have to strip off the surrounding stuff in a separate step. – Alan Moore Apr 01 '13 at 18:29

1 Answers1

7

You need to wrap your regular expression in delimiters. It's considering () to be the delimiters right now, and the . as a modifier (which is of course invalid).

"/(?=#\\$##).*?(?<=##\\$#)/"

(I'm also pretty sure the # do not need to be escaped unless you were using them as delimiters)

EDIT: You need \\ to properly escape the $ in double-quotes.

Explosion Pills
  • 183,406
  • 48
  • 308
  • 385