dimanche 20 septembre 2015

Lua Pattern Matching a pattern

Sorry for the bad title, couldn't come up with anything better.

My problem is this. I have a string containing let's say

local mystring = "ASD_ASDDFS_SDF_ASDASD as8d76 na879yd"

I want to take the part of the string that has the capital letters with the underline. Now normally this would be easy but right now this string can change from time to time. So the string could be say

local mystring = "ASD_ASDDFS_SDF as8d76 na879yd"

or local mystring = "ASD_ASDDFS_SDF_YUIOY asaasd na879yd"

Now the letters always start out as capital and are always connected using an underscore. And it's only this part I want to capture.

I thought of doing something like

local capitalpart = mystring:match("%u*%_%u*(%_%u*)+"))

So that it captures an underscore followed by capitals repeadedly. But this didn't work.

Thanks

Aucun commentaire:

Enregistrer un commentaire