Here I am again. Still trying to understand regular expressions, particularly those involving line breaks.
This time (still intending to pre-process a text file rather than print anything in a Web page), I have:
bababa
cacaca
dadada
fafafa
That is, a pattern of a pair of lines followed by a blank line. I want to remove all line breaks and separate all elements with a '#' symbol, like this:
bababa#cacaca#dadada#fafafa#...
so I apply:
$result1 = preg_replace ("/\r\n/", "#", $line);
It works. I get:
bababa#cacaca##dadada#fafafa##
Then I made an experiment:
$result1 = preg_replace ("/\r\n/", "#", $line);
$result2 = preg_replace ("/##/", "@", $result1);
I expected to get:
bababa#cacaca@dadada#fafafa@
but instead I get the same:
bababa#cacaca##dadada#fafafa##
if I try:
$result1 = preg_replace ("/\r\n/", "#", $line);
$result2 = preg_replace ("/#/", "@", $result1);
then I get:
bababa@cacaca@@dadada@fafafa@@
Question: how come a single '#' is detected and replaced but '##' is not?
Thanks,
Luciano ES
Santos, SP - Brasil