(<%a>)模式中的零件捕获尖括号,因此它们落在捕获的值中.本%a场比赛只有一个字母字符,所以你需要添加+量词以后它来搭配1个或多个字母字符.
使用
<(%a+)>%s*([^>]+)
Run Code Online (Sandbox Code Playgroud)
在%s*将匹配0+空格字符,他们会在外面集团2.
一个Lua的演示:
local function splitString(text)
return string.match(text, "<(%a+)>%s*([^>]+)")
end
print(splitString("<c> block")) -- c block
print(splitString("<category>material")) -- category material
print(splitString("decorative")) -- nil
Run Code Online (Sandbox Code Playgroud)