lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Jan 14, 2006, at 22:59, Michael T. Richter wrote:

 On Sat, 2006-14-01 at 12:10 -0600, David Gish wrote:
Such limitations are inherent to "camel case" (aka "inner-caps"). For
example, there is no way to parse "componentWithURLAndParameters" with
a simple regular expression. The solution is to use a limited
dictionary containing "URL" and any other problematic tokens.


This doesn't strike me as a robust solution.  Why not instead use two regular expressions? 

At first glance, the "URLAnd" sequence would appear problematic.

The first would find you the subtokens that are all-caps and the second would then split apart what's left at the single-cap borders.

Perhaps something along these lines:

local aString = "componentWithURLAndParameters"

aString = aString:gsub( "(%l)(%u)", "%1 %2" )
aString = aString:gsub( "(%u)(%u)(%l)", "%1 %2%3" )
aString:gsub( "%a+", print )

> component
> With
> URL
> And
> Parameters

Taken from "Programmer's Purgatory":
http://secretgeek.net/progr_purga.asp

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/