lua-users home
lua-l archive

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




On Fri, Apr 24, 2020 at 4:55 PM Shmuel Zeigerman <shmuz@013net.net> wrote:
On 24/04/2020 23:34, Russell Haley wrote:
> Hi,
>
> I'm trying to parse strings which are C function names from unit
> tests. The strings are like so:
> "test_notInit_notRealBoy_getUsed"
>
> test
> notInit
> notRealBoy
> getUsed
>
> That's simple enough: string.gmatch(mystr, "(%w+)")
>
> but sometimes the function names have a double underscore at the last
> word:
>
> "test_notInit_notRealBoy__getUsed"
>
> And I need the last underscore. The last '_' separated token
> represents a function name and they *sometimes* start with an
> underscore (I have no control over the original function names). In
> this case there is `getUsed` and a `_getUsed` function. So in the
> latter example, I'd like to get this back:
>
> test
> notInit
> notRealBoy
> _getUsed
>
> Is it possible to do that in one pass?
>
> Cheers,
> Russ
>

string.gmatch(mystr, "(_?%w+)_?")

This is better than my solution because it avoids the expensive string copying.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org