From f86bd2c5211f8162198195e97f157845fc454bc4 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Tue, 2 Apr 2024 12:16:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89=E9=83=A8=E5=88=86?= =?UTF-8?q?=20string.replace=20=E6=B5=8B=E8=AF=95=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/String.uts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index 1c226a1..8b347f1 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -189,13 +189,14 @@ export function testString(): Result { 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.'); + // 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); // expect(newString).toEqual("abc - 12345 - #$*%"); // const str1 = 'hello, world'; -- GitLab