What Delimiter to use for preg_replace in PHP (replace working outside of PHP but not inside)?

Preg_replace() requires a delimiter character: preg_replace("/$pat/" ... Traditionally it's the forward slash, but it can be any character - especially when you need the forward slash in the regex itself you can resort to another character. This flexibility allows you to express "/http:\/\/foo\/bar\//" ("leaning toothpick syndrome") as "! http://foo/bar/!".

The delimiter character is necessary to separate the regex from the regex flags (a.k.a."modifiers"), for example: preg_replace("/$pat/i" ... …this uses the I flag to declare a case-insensitive regex.

Thank you so much, this sorted it and it now all makes sense. It was also failing because the pipes were ||... so it's good to view-source too =) – Pauly Pops Dec 1 '10 at 12:43.

From the PHP manual on PCRE delimiters: A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character. Often used delimiters are forward slashes (/), hash signs (#) and tildes (~). So you could use / as delimiter to separate the pattern from optional modifiers: /\\(.*)\|\|(.*)\\/ But also note: In addition to the aforementioned delimiters, it is also possible to use bracket style delimiters where the opening and closing brackets are the starting and ending delimiter, respectively.

Furthermore, currently your pattern will match as much as possible as both quantifiers are greedy; you might want to change them to be reluctant to only match as little as possible: /\\(.*? )\|\|(.*? )\\.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions