From c7760c230b580b66412610e8164c1ba78e3b9de0 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 27 Mar 2024 18:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20string.replace=20=E6=B5=8B?= =?UTF-8?q?=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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/uni_modules/uts-tests/utssdk/String.uts b/uni_modules/uts-tests/utssdk/String.uts index a6a057a..4eccc9d 100644 --- a/uni_modules/uts-tests/utssdk/String.uts +++ b/uni_modules/uts-tests/utssdk/String.uts @@ -188,6 +188,14 @@ export function testString(): Result { expect(string).toEqual(str); 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); // expect(newString).toEqual("abc - 12345 - #$*%"); // const str1 = 'hello, world'; -- GitLab