Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] OT: Match newline character within [ ] in a regularexpression From: Manuel Lemos (mlemos <email protected>)
Date: 03/25/99

Hello Rasmus,

On 25-Mar-99 07:50:51, you wrote:

>> It seems [\n] wouldn't work because \ and n are treated literally.

>Untrue.

>Try this simple test:

> $a = "abd\n123";
> $b = ereg_replace("[b\n2]","-",$a);
> echo $b;

>This will show: a-d-1-3

>Which shows that the \n is being found correctly.

No, what you are using is the newline character that PHP
parser converts to the character with code 10. As I mentioned I can't use
because I am reading the regular expressions from a file and they have to
be already escaped for newline or other special characters as those
characters confuse the code that reads the file.

Regular expressions are tricky especially in cases like this that the
language string escaping gets in the way. I read in re_format man page
that \ looses special meaning within a sequence []. But it seems now that
the problem is more of mixing language with regular expression escaping.

So, now I am confused wether the string is is PHP that does the escaping or
is the regular expression code. It seems only PHP does escaping as the
regular expression string represented in a PHP source file as "\\n" does not
match a "\n" string.

Anyway what I need is to be able to read a regular expression string from a
file and use it as matching string in a PHP program. The matching string must
be read from the file without hard new lines, ie, any new lines or other
special characters must be escaped as described in the documentation for
regular expressions. So, new line must be represented in the file by the
characters \ and n right to each other.

I wonder if I can use any of the existing PHP functions to convert all the
regular expressions special character sequences to some form that PHP
ereg() takes them as literal characters the sequences represent.

Regards,
Manuel Lemos

E-mail: mlemos <email protected>
URL: http://www.e-na.net/the_author.html
PGP key: finger://mlemos <email protected>

--

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>