Re: Regular expression for correcting proper nouns
| From: | CC Zona | Date: | Thu, 18 Jul 2002 04:29:42 +0000 |
| Subject: | Re: Regular expression for correcting proper nouns | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108203@lists.php.net to get a copy of this message | ||
In article <20020717120934.90119.qmail@pb1.pair.com>,
henry@teacake.f9.co.uk (Henry) wrote:
> I'm looking for a simple was to correct a list of proper nouns given all in
> lower case!
>
> For example
>
> given $string="london paris rome";
>
> I would like "London Paris Rome".
>
> However there is one cavet; if the word already has a captital anywhere in
> it, it should be left alone!!!
>
> Is there a soultion using regular expressions?
Yes. The topics you'll want to look at (in the PCRE chapter of the manual)
are: case-sensitivity, character classes, capturing subpatterns, and the
documentation for preg_replace_callback(). One of the things you'll need
to do is define for yourself what constitutes a "word" for your purposes.
Does a single letter word get counted as a "word" (i.e. "i")? Is there any
non-alphabet character that can validly appear within the thing you call a
word (i.e. "hi-fi", "mst3k")? This is why there's no single ready-made
solution.
> Also is there one for removing multiple spaces?
>
> i..e given "A B C D E" it would give "A B C D E".
Yes. Again, character classes will be your friend, as will preg_replace().
Just decide which of the whitespace characters you mean to include in that
definition of "multiple spaces"...
--
CC