提交 c7760c23 编写于 作者: 杜庆泉's avatar 杜庆泉

增加 string.replace 测试示例

上级 44170e9a
...@@ -188,6 +188,14 @@ export function testString(): Result { ...@@ -188,6 +188,14 @@ export function testString(): Result {
expect(string).toEqual(str); expect(string).toEqual(str);
return p.join(' - '); return p.join(' - ');
} }
const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g
const formatStr = 'This is a [sample] text with [another] capture group.'
const nextStr = formatStr.replace(REGEX_FORMAT, (match:string, p1: string|null, offset: number, string: string):string =>{
console.log('123', p1, match)
return p1 ?? match ?? ''
})
expect(nextStr).toEqual('This is a sample text with another capture group.');
// var newString = str.replace(/([^\d]*)(\d*)([^\w]*)/, replacer); // var newString = str.replace(/([^\d]*)(\d*)([^\w]*)/, replacer);
// expect(newString).toEqual("abc - 12345 - #$*%"); // expect(newString).toEqual("abc - 12345 - #$*%");
// const str1 = 'hello, world'; // const str1 = 'hello, world';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册