1

I have a string that contains only digits from 2 to 9, like '223488875662264442', it is guaranteed that it does not contain more than 3 adjacent similar digits, for example, it cannot contain '7777', but it can contain '27747772'.

I want to make a pattern that matches all the similar consecutive numbers, example:

    > str = '44788895532244474568884511123331566';
    > for n in string.gmatch(str,pat) do -- pat is the pattern
    >>    print(n);
    > end
    44
    7
    888
    9
    55
    ...

tried with patterns like '(%d)%1*' with no success.

I cannot use regex,I need to do it with Lua patterns.

Redouane Red
  • 509
  • 1
  • 5
  • 13

0 Answers0