Regular Expression help

I’m trying to make a regular expression that will find a character that I specify and then return all numbers after it, but stop before the next letter. Right now i’m using,


self.DNA = “A99B26C101D2E89” --Example String
traitValue = string.gmatch(string.gmatch(self.DNA, trait … “%d*”)(), “%d”)
– Returns 9 for A and 2 for B etc
– Needs to return 99 for A 26 for B, 101 for C, etc


and it returns one number, but i need all numbers till the next letter, I’ve tried adding a * to the second expression, I’m using 2 expressions because I just want the number for my next function. I’m pretty sure someone who understand this better could do it in one, but that’s not me. Any help is appreciated, thanks in advance.

[lua]local DNA = “A99B26C101D2E89”
for index , match in string.gmatch(DNA, “(%w-)(%d+)”)do
print(index , match)

A	99
B	26
C	101
D	2
E	89

And this is the exact solution:

[lua]traitValue = self.DNA:match( trait … “(%d+)” )[/lua]

Thanks for the replies, I went with the one liner, cause I only need to match one at a time, but the first one does help me understand the reg. exp. better.


Actually, I will need to use both methods, thanks again!