Re: Regular Expressions.

From: Date: Tue, 20 Nov 2001 14:46:07 +0000
Subject: Re: Regular Expressions.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-75246@lists.php.net to get a copy of this message
You don't have to start with /, because you can start with |, ~, or something else which does not appear in the regex string. The idea is the first character must be and the last. ----- Original Message ----- From: "Stefan Rusterholz" <scripting@interaktion.ch> To: "Jeff Lewis" <jeff@hyrum.net> Cc: "PHP" <php-general@lists.php.net> Sent: Tuesday, November 20, 2001 4:33 PM Subject: Re: [PHP] Regular Expressions. > I ran into that problem also when I first tried to script with PHP. > 1. > preg_match("/yourexpression/",$text,$matches); > always set the / at beginning and end of the regex (as you did in perl) > 2. > preg_match("/\[/",.... > this won't match the char [ because of the double-quotes (") it escapes > the [-char only "one-time" (don't know how to say that) > to get it working as you know it from perl you have to escape it twice: > preg_match("/\\[/"... > 3. > AFAIK the pattern-modifier /g is always set! Use the LIMIT parameter to > avoid /g > > there have been some more problems during my transition, but I don't > remember all of them... > read the user comments on the documention on php.net, they are very helpful > > hope I could help > Stefan Rusterholz, s.rusterholz@interaktion.ch > ---------------------------------- > interaktion gmbh > Stefan Rusterholz > Zürichbergstrasse 17 > 8032 Zürich > ---------------------------------- > T. +41 1 253 19 55 > F. +41 1 253 19 56 > W3 www.interaktion.ch > ---------------------------------- > ----- Original Message ----- > From: "Jeff Lewis" <jeff@hyrum.net> > To: <php-general@lists.php.net> > Sent: Tuesday, November 20, 2001 2:37 PM > Subject: [PHP] Regular Expressions. > > > I'm trying to port over some Perl to PHP and have come to a string of > regular expressions like this. There are probably 30 of them: > > $message =~ s~\[color=([\w#]+)\](.*?)\[/color\]~<font > color="$1">$2</font>~isg; > $message =~ s~\[black\](.*?)\[/black\]~<font color=000000>$1</font>~isg; > $message =~ s~\[white\](.*?)\[/white\]~<font color=FFFFFF>$1</font>~isg; > > How can I accomplish the same in PHP? > > $message = preg_match ("\[color=([\w#]+)\](.*?)\[/color\]", "<font > color="$1">$2</font>") > > I was thinking that is how it would be done but I am getting errors. > > Jeff > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#75246) next »