Reply to Re: Regex help with removing double quotes

Your name:

Reply:


Posted by Schroeder, AJ on 11/05/07 20:40

Justin Koivisto wrote:
> Schroeder, AJ 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 = '[^"]'; <--- removes the beginning double quote
>> $pattern = '["$]'; <--- removes the ending double quote
>>
>> But when I try to make this all one statement with:
>>
>> $pattern = '[^"].*["$]';
>>
>> PHP throws a warning with an unknown modifier '.'. I then tried to
>> enclose '.*' in parentheses and I get an unknown modifier '('.
>>
>> This is getting beyond my regex knowledge, if anyone has any advice
>> on this it would be greatly appreciated.
>>
>> Thanks in advance,
>>
>> AJ Schroeder
>>
>>
>
> when using preg_* you need escape chars for the expression....
>
> your first patterns should look something like:
>
> $pat = '`^"`'; // quote at beginning of string
>
> $pat = '`"$`'; // quote at end of string
>
> $pat = '`^"(.*)"$`'; // single-line string that starts and ends with
> a quote

Hmm, maybe I am that dense, but that last expression seemed to torch the
entire string and return nothing. The first two work no problem.

Still confused...

[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

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