|
Posted by erikcw on 02/23/07 20:32
Hi all,
I'm trying to write a regex pattern to use in preg_replace. Basically
I want to put [brackets] around every line (\n) in this variable.
However, I need to exclude lines that already have brackets or
quotation marks around them as well as lines that start with a
hyphen. Lastly the lines with ** need the brackets before the **,
instead of at the end of the line.
Here is what I have so far - it is close, but I keep ending up with
duplicate brackets.
$temp = 'this
is
a
test
"this"
"is"
"a"
[this]
[is]
[a]
test ** 93.23
test 2 ** 10.05
-this
-is
-a
another good test
';
$PATTERNS = array("/^[^\"\[]/m", "/[^\"\]]$/m", "/[\r\n]+/", "/ \*\*
(.*)]/");
$REPLACEMENTS = array("[", "]", "]\n[", "] \*\* $1");
$output1 = trim(preg_replace($PATTERNS, $REPLACEMENTS, trim($temp)));
print_r($output1);
Thanks for your help!
Erik
[Back to original message]
|