1 回答
TA贡献1839条经验 获得超15个赞
这两者似乎都具有相当的性能。第一个假设每个块中的数字数量已知(5、6、5)。第二个是原始正则表达式的清理版本,它接受 3 个由连字符分隔的任意数量的数字序列。
// assumes ABC - 5 digits - 6 digits - 5 digits
const regex = /([A-Z]{2,3}-[\d]{5}-[\d]{6}-[\d]{5})/g;
// your original regex with unnecessary stuff stripped out.
// notice that this captures the second item with 999 appended that the first expression doesn't get.
const regex2 = /([A-Z]{2,3}(?:-[0-9]+){3})/g;
const input = "asfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312999afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12345afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-99999-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfdsasfsfdasABC-12312-121231-12312afsasfsdfds";
console.log(input.match(regex));
console.log(input.match(regex2));
添加回答
举报