You are here: Re: [PHP] Regular expression question « PHP « IT news, forums, messages
Re: [PHP] Regular expression question

Posted by Robin Vickery on 08/12/05 11:39

On 8/11/05, Leon Vismer <lvismer@tasmer.co.za> wrote:
> Hi Robin
>
> Many thanks for this,
>
> how would one extend this to support the following:
> $str = "insert into userComment (userID, userName, userSurname) values (0,
> 'Leon', 'mcDonald')";
>
> one does not want
>
> $str = "insert into user_comment (user_id, user_name, user_surname) values (0,
> 'Leon', 'mc_donald')";

$match = '/(?<=[a-z])(?<![Mm]c|[Mm]ac)([A-Z]+)/e';

Should make exceptions for "McDonald", "mcDonald", "MacDonald" and "macDonald".

With luck you don't have any tables called something like "appleMacUsers".

> unfortunately lookbehind assertions does not support non-fixed length chars so
> /(?<=(?<!')[a-z])([A-Z]+)/e will work for 'mDonald' but the following will not
> work.

True, lookbehind assertions must be a fixed length - but unlike in
perl, they can have alternates which are different fixed lengths:

This is illegal, because the length isn't fixed: (?<![Mm]a?c)

This is fine, because each alternate is fixed even though they are
diffferent lengths: (?<![Mm]c|[Mm]ac)

-robin

 

Navigation:

[Reply to this 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

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