必须有一个可以使用的功能,它将极大地简化所有这些非常相似的替换。希望能够制作一个能够处理今年秋季所有收缩的功能,包括我,可能等等。
// for can't
s = s.replace(/cant/g, "ca{n't|n{| }not}");
s = s.replace(/can't/g, "ca{n't|n{| }not}");
s = s.replace(/Cant/g, "Ca{n't|n{| }not}");
s = s.replace(/Can't/g, "Ca{n't|n{| }not}");
//for can not
s = s.replace(/can not/g, "ca{n't|{| }not}");
s = s.replace(/Can not/g, "Ca{n't|{| }not}");
// for won't
s = s.replace(/wont/g, "w{on't|ill not}");
s = s.replace(/won't/g, "w{on't|ill not}");
s = s.replace(/Wont/g, "W{on't|ill not}");
s = s.replace(/Won't/g, "W{on't|ill not}");
// for will not
s = s.replace(/will not/g, "w{on't|ill not}");
s = s.replace(/Will not/g, "W{on't|ill not}");
// for hasn't
s = s.replace(/hasnt/g, "has{n't| not}");
s = s.replace(/hasn't/g, "has{n't| not}");
s = s.replace(/Hasnt/g, "Has{n't| not}");
s = s.replace(/Hasn't/g, "Has{n't| not}");
// for has not
s = s.replace(/has not/g, "has{n't| not}");
s = s.replace(/Has not/g, "Has{n't| not}");