regular expression problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I work on some bbcode parser script and i have difficulty to find out how to
parse hyphens to horizontal

for example

in text i have


and I'll like to convert this into "<br/><hr><br/><br/>"

i try to use regular expression like

// $pattern="\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+?";
// $replacement="<br/>----------------------------------------<br/><br/>";


$input=preg_replace($pattern, $replacement, $input);

but i allways get error Delimiter must not be alphanumeric or backslash

Re: regular expression problem

Atomic escribió:
Quoted text here. Click to load it

Your regexp is missing the delimiter, which is should be the first
character in the string, and PHP believes you want to use \ as
delimiter, which is not a valid character.

Regular expressions are composed of a pattern plus zero or more
modifiers. Since you must stuff it all inside a string, you have to
enclose the pattern between a delimiter character so PHP knows where the
modifiers start. For instance, to match [a-z]+ with the case-insensible
modifier, you write this:


You can choose the delimiter, though. All these are valid:


It's explained here:

This should do the trick (not tested!):

$pattern = '/-/';

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Re: regular expression problem

On 31 July, 10:15, "=C1lvaro G. Vicario"
Quoted text here. Click to load it

Not forgetting the very useful preg_quote() function for protecting
your delimiter.

Site Timeline