[thelist] Parsing camelcase text

Jack Timmons jorachim at gmail.com
Mon Jan 12 10:32:22 CST 2009

On Mon, Jan 12, 2009 at 9:29 AM, misterhaan <misterhaan at track7.org> wrote:

> Matt McKeon wrote:
> > I thought the .*? bit would have caught the next characters, but
> > apparently not.
> >
> the dot means any character, the star means any number of the previous
> character, and the question mark after the star means the shortest
> possible match.  so .*? will always match a 0-length string.  instead of
> .*? i'd probably go for [^A-Z]* for any number of characters that aren't
> capital letters.
> --

Sorry for the wait, craziness at work.

$pattern = "/([A-Z][a-z0-9]+)/";
$string = "MyTestString";

preg_match_all($pattern, $string, $matches);

That should do it. Couldn't test it before, sorry.

Note: That doesn't catch special characters, FYI. Let me know if what you
need changes.


-Jack Timmons
Twitter: @jorachim

More information about the thelist mailing list