Reply to Re: Regex help with removing double quotes

Your name:

Reply:


Posted by Rik Wasmus on 11/05/07 20:56

On Mon, 05 Nov 2007 20:11:49 +0100, Schroeder, AJ <aj1@qg.com> wrote:

> Hello group,
>
> I am attempting to remove double quotes from the beginning and ending =
of =

> a
> string. Admittedly, I am not the best with regular expressions, but I =
do
> have two that work with preg_replace(). Here they are:
>
> $pattern =3D '[^"]'; <--- removes the beginning double quote
> $pattern =3D '["$]'; <--- removes the ending double quote
>
> But when I try to make this all one statement with:
>
> $pattern =3D '[^"].*["$]';
>
> PHP throws a warning with an unknown modifier '.'. I then tried to =

> enclose
> '.*' in parentheses and I get an unknown modifier '('.

Yes indeed.
The preg_* function expect a pattern like this:
(delimiter)(pattern)(delimiter)(modifiers)

You are free to choose your own delimiter ('/' is pretty standard), and =
a =

second occurance of that character is assumed to end the pattern and sta=
rt =

the modifiers. (I'm actually quite ammazed it matches '[' to ']', a quit=
e =

rigid implementation would throw an error stating that " was an unknown =
=

modifier).

$string =3D preg_replace('/(^"+|"+$)/','',$string);
-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация