Unexpected ereg_replace when trying to match newline

0 views
Skip to first unread message

DuCakedHare

unread,
Jun 4, 2009, 6:18:00 AM6/4/09
to Regex
Hi,

In PHP 5.2.6 : I'm trying to replace any dot character found at the
start of a line with two dots.

Since I cannot find a way to make ^ match newlines within a string, I
am doing:

ereg_replace('(\r|\n)\.','\1..',"first line\r\n.\r\nsecond line");

This however still seems not to match - the dot is never replaced.

I believe the regex is constructed correctly, and even so basic, I
still cannot determine what is wrong...

DuCakedHare

unread,
Jun 5, 2009, 9:40:00 AM6/5/09
to Regex
I solved it on my own.

ereg family does not use the extended features of grep.

I also had problem where replacing whitespace using \s would replace
's' characters instead.

Instead, use preg family and all seems to work.
Reply all
Reply to author
Forward
0 new messages