RAFASU

re

re = require 'aegisub.re'.

str (string)
first (number)
str
last (number)
str
>>> re.match("b", "abc")
{
    {
        ["str"] = "b",
        ["first"] = 2,
        ["last"] = 2
    }
}

re.compile

re.ICASE
re.NOSUB:
re.NEWLINE_ALT:
re.NO_MOD_M:
re.MOD_S:
re.MOD_X:
re.NO_EMPTY_SUBEXPRESSION:
>>> re.match("a", "A")
nil
>>> re.match("a", "A", re.ICASE, re.NOSUB)
{
    {
        ["str"] = "A",
        ["first"] = 1,
        ["last"] = 1
    }
}

re.compile

expr = re.compile(pattern, [FLAGS])

@pattern (string)
expr (table)
>>> expr = re.compile("a")
>>> expr:split("banana")
{
    "b",
    "n",
    "n"
}

re.split

chunks = re.split(str, pattern, skip_empty=false, max_splits=0)

pattern.

@str (string)
@pattern (string)
@skip_empty (boolean)
@max_splits (number)
#chunksmax_splits + 1).
chunks (table)
strpattern.

>>> re.split(",", "a,,b,c")
{
    "a",
    "",
    "b",
    "c"
}
>>> re.split(",", "a,,b,c", true)
{
    "a",
    "b",
    "c"
}
>>> re.split(",", "a,,b,c", false, 1)
{
    "a",
    ",b,c",
}

re.gsplit

iter = re.gsplit(str, pattern, skip_empty=false, max_splits=0)

@str (string)
@pattern (string)
@skip_empty (boolean)
@max_splits (number)
#chunksmax_splits + 1).
iter (iterator over strings)
strpattern.

>>> for str in re.gsplit(",", "a,,b,c") do
>>>     print str
>>> end
a

b
c
>>> for str in re.gsplit(",", "a,,b,c", true) do
>>>     print str
>>> end
a
b
c
>>> for str in re.gsplit(",", "a,,b,c", false, 1) do
>>>     print str
>>> end
a
,b,c

re.find

matches = re.find(str, pattern)

strpattern.

@str (string)
@pattern (string)
matches (table or nil)
nil
>>> re.find(".", "☃☃")
{
    {
        ["str"] = "☃",
        ["first"] = 1,
        ["last"] = 3
    },
    {
        ["str"] = "☃",
        ["first"] = 4,
        ["last"] = 6
    }
}
function contains_an_a(str) if re.find("a", str)
        print "Has an a" else print "Doesn't have an a" end end
>>> contains_an_a("abc")
Has an a
>>> contains_an_a("def")
Doesn't have an a

re.gfind

iter = re.gfind(str, pattern)

strpattern.

@str (string)
@pattern (string)
iter (iterator over string, number, number)
>>> for str, start_idx, end_idx in re.gfind(".", "☃☃") do
>>>     print string.format("%d-%d: %s", start_idx, end_idx, str)
>>> end 1-3: ☃
4-6: ☃

re.match

matches = re.match(str, pattern)

findfind

@str (string)
@pattern (string)
matches (table or nil)
nilMatch Table
>>> re.match("(\d+) (\d+) (\d+)", "{250 1173 380}Help!")
{
    {
        ["str"] = "250 1173 380",
        ["first"] = 2,
        ["last"] = 13
    },
    {
        ["str"] = "250",
        ["first"] = 2,
        ["last"] = 4
    },
    {
        ["str"] = "1173",
        ["first"] = 6,
        ["last"] = 9,
    },
    {
        ["str"] = "380"
        ["first"] = 11,
        ["last"] = 13
    }
}

re.gmatch

iter = re.gmatch(str, pattern)

re.match.

@str (string)
@pattern (string)
matches (iterator over table)

re.sub

out_str, rep_count = re.sub(str, replace, pattern, max_count=0)

patternstrreplace.

@pattern (string)
@replace (string , function)

@max_count (number)
out_str (string)
rep_count (number)

>>> re.sub("{\\k10}a{\\k15}b{\\k30}c", "\\\\k", "\\kf")
{\kf10}a{\kf15}b{\kf30}c

>>> re.sub("{\\K10}a{\\K15}b{\\k30}c", "\\\\k", "\\kf", re.ICASE)
{\kf10}a{\kf15}b{\kf30}c

function add_one(str) return tostring(tonumber(str) + 1)
end
>>> re.sub("{\\k10}a{\\k15}b{\\k30}c", "\\\\k(\[[:digit:]]+)", add_one)
{\k11}a{\k16}b{\k31}c