You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/utils/searchStringsBetween.ts

13 lines
507 B

function searchStringsBetween(str: string, prefix: string, suffix: string): string[]
{
// 转义特殊字符并构建正则表达式,忽略大小写
const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const escapedSuffix = suffix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(escapedPrefix + ".*?" + escapedSuffix, "gi");
// 存储满足条件的字符串的数组
const filteredStrings = str.match(regex) || [];
return filteredStrings;
}