单个字符 格式
- [set] 匹配 s、e、t
- [^set] 取反 不匹配s、e、t
- [a-d] 设置匹配范围 匹配a、b、c、d
- [^a-d] 匹配范围 取反 不匹配a、b、c、d
- .匹配 任意字符 不匹配 \n
- \char 匹配转义字符
案例
string delimited = "[set]";
string input = "tuesday";
var matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
delimited = "[^set]";
matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
input = "abecdf";
delimited = "[a-d]";
matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
delimited = "[^a-d]";
matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
input = "\"abcd\nefg";
delimited = ".";
matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
delimited = "\"";
matches = Regex.Matches(input, delimited);
PrintMatchResult(matches);
void PrintMatchResult(MatchCollection matches)
{
Debug.Log($"<color=#00ff00>匹配数目:{matches.Count}</color>");
foreach (Match match in matches)
{
Debug.Log("匹配結果:" + match.Value);
}
}