3

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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Thomja
  • 259
  • 5
  • 15

1 Answers1

4

You can use the following pattern:

[%u_]+
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
karthik manchala
  • 13,492
  • 1
  • 31
  • 55
  • 1
    It should be noted that; that would be the only pattern required. `local capitalpart = mystring:match "^([%u_]+)"` – hjpotter92 Sep 20 '15 at 19:39