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.

0

1 Answer 1

4

You can use the following pattern:

[%u_]+
Sign up to request clarification or add additional context in comments.

1 Comment

It should be noted that; that would be the only pattern required. local capitalpart = mystring:match "^([%u_]+)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.