A match if something else is not preceded by something else

I am trying to parse a string and extract some numbers from it. In principle, any 2-3 digits should be matched, with the exception of those that have a "TEST" in front of them. Here are some examples:

TEST2XX_R_00.01.211_TEST => 00, 01, 211
TEST850_F_11.22.333_TEST => 11, 22, 333
TESTXXX_X_12.34.456      => 12, 34, 456

Here are some of the things I've tried:

(?<!TEST)[0-9]{2,3} - ignores only the first digit after TEST

_[0-9]{2,3}|\.[0-9]{2,3} - Correctly matches numbers, but matches the character in front of them (_ or.).

I know that this may be a duplicate of a regular expression to match something if it is not preceded by something else , but I could not get my answer there.

+4
source share
1 answer

, , Lua ( , , , TEST%d+|(%d+) Lua, Lua ).

, TEST + , :

local s = "TEST2XX_R_00.01.211_TEST"
for x in string.gmatch(s:gsub("TEST%d+",""), "%d+") do  
    print(x)
end

Lua

s:gsub("TEST%d+","") TEST<digits>+ %d+, string.gmatch, .

+1

Source: https://habr.com/ru/post/1687003/


All Articles