RE: [PHP] ereg problem?

This is a discussion on RE: [PHP] ereg problem? within the PHP General forums, part of the PHP Programming Forums category; > -----Original Message----- > From: sven [mailto:svenie@gmx.li] > Sent: 25 July 2003 10:35 > > by ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-25-2003
Mike Ford
 
Posts: n/a
Default RE: [PHP] ereg problem?

> -----Original Message-----
> From: sven [mailto:svenie@gmx.li]
> Sent: 25 July 2003 10:35
>
> by the way, it's to complicated. the brackets [ and ] are used for
> cha-groups. you can leave them for only one char. so this
> would be the same:
> "\\n" (you have to escape the backslash with a backslash)


And then we get into the typical
double-quoted-regexp-backslash-proliferation problem -- the above will pass
\n as the regexp, which matches a newline *not* the intended literal \n. So
now you have to escape the escaped escape, to get:

"\\\\n"

Which passes \\n as the regexp, which does indeed match a literal \n !

Another way to go is to use single quotes around the regexp, since a
single-quoted string does not interpret \-expressions (except for \', of
course!) -- so this is the same regexp as above:

'\\n'

I know which I prefer, but YMMV of course!

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0