14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci/* 174514f5e3Sopenharmony_ci * @tc.name:regexp 184514f5e3Sopenharmony_ci * @tc.desc:test Regexp 194514f5e3Sopenharmony_ci * @tc.type: FUNC 204514f5e3Sopenharmony_ci * @tc.require: issueI5NO8G 214514f5e3Sopenharmony_ci */ 224514f5e3Sopenharmony_ci{ 234514f5e3Sopenharmony_ci let str = ""; 244514f5e3Sopenharmony_ci let regexp = /[]/; 254514f5e3Sopenharmony_ci print(JSON.stringify(str.replace(regexp,"b"))); 264514f5e3Sopenharmony_ci} 274514f5e3Sopenharmony_ci{ 284514f5e3Sopenharmony_ci let str = ""; 294514f5e3Sopenharmony_ci let regexp = /[]/g; 304514f5e3Sopenharmony_ci print(JSON.stringify(str.replace(regexp,"b"))); 314514f5e3Sopenharmony_ci} 324514f5e3Sopenharmony_ci{ 334514f5e3Sopenharmony_ci let str = ""; 344514f5e3Sopenharmony_ci let regexp = /[]/u; 354514f5e3Sopenharmony_ci print(JSON.stringify(str.replace(regexp,"b"))); 364514f5e3Sopenharmony_ci} 374514f5e3Sopenharmony_ci{ 384514f5e3Sopenharmony_ci let str = ""; 394514f5e3Sopenharmony_ci let regexp = /[\]/; 404514f5e3Sopenharmony_ci print(JSON.stringify(str.replace(regexp,"b"))); 414514f5e3Sopenharmony_ci} 424514f5e3Sopenharmony_ci 434514f5e3Sopenharmony_ci 444514f5e3Sopenharmony_civar reg = /[\x5d-\x7e]/i; 454514f5e3Sopenharmony_civar result = reg.test("a"); 464514f5e3Sopenharmony_ciprint(result); 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_civar reg1 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$"); 494514f5e3Sopenharmony_civar result1 = reg1.test('0٫0000000000001'); 504514f5e3Sopenharmony_ciprint(result1); 514514f5e3Sopenharmony_ci 524514f5e3Sopenharmony_civar reg2 = /^[Α-ώ]+$/i 534514f5e3Sopenharmony_ciprint(reg2.test('άέήίΰϊϋόύώ')); 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ciprint(reg2.test('ΆΈΉΊΪΫΎΏ')); 564514f5e3Sopenharmony_ci 574514f5e3Sopenharmony_ciprint(reg2.test('αβγδεζηθικλμνξοπρςστυφχψω')); 584514f5e3Sopenharmony_ci 594514f5e3Sopenharmony_ciprint(reg2.test('ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ')); 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_cilet reg3 =/^[A-Z0-9_\-]*$/i 624514f5e3Sopenharmony_ciprint(reg3.test('')) 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_cilet reg4 = new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>https?[::]//[^/]+/svn(?:/[a-z0-9.,;?'*:+&%$#=~_ \\u4E00-\\u9FA5-]*)*).*$", "i") 654514f5e3Sopenharmony_ciprint(reg4.test('a')); 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_cilet reg5 = new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>(?:(?:ht|f)tps?[::]//)?(?:[a-z0-9-]+\\.)+" + "(?:com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|cn|cc|tw|de|au|sg|hk|ei|fr|me|im)(?![a-z])" + "(?:\\:[0-9][0-9]*)?(?:\\.?/[a-z0-9.,;?'\\|*:\\\\+&%$#=~_-]*)*).*$", "i") 684514f5e3Sopenharmony_ciprint(reg5.test('a')); 694514f5e3Sopenharmony_ci 704514f5e3Sopenharmony_cilet reg6 = new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>(?:ht|f)tps?[::]//(?:[a-z0-9-]+\\.)*[a-z0-9-]+(?:/[a-z0-9]+)*[/a-z0-9.,;?'\\|*:\\\\+&%$#=~_-]*).*$", "i") 714514f5e3Sopenharmony_ciprint(reg6.test('a')); 724514f5e3Sopenharmony_ci 734514f5e3Sopenharmony_cilet reg7 = new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>(?:https?[::]//)?(?:[a-z0-9-\\\\]+\\.)+" + "(?:com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|cn|cc|tw|de|au|sg|hk|ei|fr|me|im)(?![a-z])" + "(?:\\:\\d{4})?(?:/[a-z0-9.,;?'\\|*:\\\\+&%$#=~_-]*)*\\?(?:[a-z0-9]*=[a-z0-9.,;?'*:+%$#=~_\\u4E00-\\u9FA5-]*&?)*).*$", "i") 744514f5e3Sopenharmony_ciprint(reg7.test('a')); 754514f5e3Sopenharmony_ci 764514f5e3Sopenharmony_cilet arr = [] 774514f5e3Sopenharmony_cilet temp = true 784514f5e3Sopenharmony_civar quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i; 794514f5e3Sopenharmony_ciarr.push(quotedEmailUserUtf8.test(" foo m端ller ")) 804514f5e3Sopenharmony_ci 814514f5e3Sopenharmony_cilet reg8 = /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i 824514f5e3Sopenharmony_ciarr.push(reg8.test('palíndromo')) 834514f5e3Sopenharmony_ciarr.push(reg8.test('órgão')) 844514f5e3Sopenharmony_ciarr.push(reg8.test('qwértyúão')) 854514f5e3Sopenharmony_ciarr.push(reg8.test('àäãcëüïÄÏÜ')) 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_cilet reg9 = /^[A-ZÀÉÈÌÎÓÒÙ]+$/i 884514f5e3Sopenharmony_ciarr.push(reg9.test('àéèìîóòù')) 894514f5e3Sopenharmony_ciarr.push(reg9.test('metró')) 904514f5e3Sopenharmony_ciarr.push(reg9.test('pèsca')) 914514f5e3Sopenharmony_ciarr.push(reg9.test('genî')) 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_cilet reg10 = /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i 944514f5e3Sopenharmony_ciarr.push(reg10.test('thiến')) 954514f5e3Sopenharmony_ciarr.push(reg10.test('nghiêng')) 964514f5e3Sopenharmony_ciarr.push(reg10.test('chào')) 974514f5e3Sopenharmony_ciarr.push(reg10.test('thế')) 984514f5e3Sopenharmony_ciarr.push(reg10.test('giới')) 994514f5e3Sopenharmony_ci 1004514f5e3Sopenharmony_cilet reg11 = /^[A-ZÅÄÖ]+$/i 1014514f5e3Sopenharmony_ciarr.push(reg11.test('äiti')) 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_cilet reg12 = /^[A-ZÆØÅ]+$/i 1044514f5e3Sopenharmony_ciarr.push(reg12.test('aøå')) 1054514f5e3Sopenharmony_ci 1064514f5e3Sopenharmony_cilet reg13 = /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i 1074514f5e3Sopenharmony_ciarr.push(reg13.test('kreską')) 1084514f5e3Sopenharmony_ciarr.push(reg13.test('zamknięte')) 1094514f5e3Sopenharmony_ciarr.push(reg13.test('zwykłe')) 1104514f5e3Sopenharmony_ciarr.push(reg13.test('kropką')) 1114514f5e3Sopenharmony_ciarr.push(reg13.test('przyjęły')) 1124514f5e3Sopenharmony_ciarr.push(reg13.test('święty')) 1134514f5e3Sopenharmony_ciarr.push(reg13.test('Pozwól')) 1144514f5e3Sopenharmony_ci 1154514f5e3Sopenharmony_cilet reg14 = /^[А-ЯЂЈЉЊЋЏ]+$/i 1164514f5e3Sopenharmony_ciarr.push(reg14.test('ШћжЂљЕ')) 1174514f5e3Sopenharmony_ci 1184514f5e3Sopenharmony_cilet reg15 = /^[A-ZČĆŽŠĐ]+$/i 1194514f5e3Sopenharmony_ciarr.push(reg15.test('ŠAabčšđćž')) 1204514f5e3Sopenharmony_ciarr.push(reg15.test('ŠATROĆčđš')) 1214514f5e3Sopenharmony_ci 1224514f5e3Sopenharmony_cilet reg16 = /^[A-ZÁÉÍÑÓÚÜ]+$/i 1234514f5e3Sopenharmony_ciarr.push(reg16.test('ábcó')) 1244514f5e3Sopenharmony_ciarr.push(reg16.test('dormís')) 1254514f5e3Sopenharmony_ciarr.push(reg16.test('volvés')) 1264514f5e3Sopenharmony_ciarr.push(reg16.test('español')) 1274514f5e3Sopenharmony_ci 1284514f5e3Sopenharmony_cilet reg17 = /^[A-ZÅÄÖ]+$/i 1294514f5e3Sopenharmony_ciarr.push(reg17.test('religiös')) 1304514f5e3Sopenharmony_ciarr.push(reg17.test('stjäla')) 1314514f5e3Sopenharmony_ciarr.push(reg17.test('västgöte')) 1324514f5e3Sopenharmony_ci 1334514f5e3Sopenharmony_cilet reg18 = /^[A-ZÇĞİıÖŞÜ]+$/i 1344514f5e3Sopenharmony_ciarr.push(reg18.test('AİıÖöÇ窺ĞğÜüZ')) 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_cilet reg19 = /^[Α-ώ]+$/i 1374514f5e3Sopenharmony_ciarr.push(reg19.test('άέήίΰϊϋόύώ')) 1384514f5e3Sopenharmony_ciarr.push(reg19.test('ΆΈΉΊΪΫΎΏ')) 1394514f5e3Sopenharmony_ci 1404514f5e3Sopenharmony_cilet reg20 = /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i 1414514f5e3Sopenharmony_ciarr.push(reg20.test('Azərbaycan')) 1424514f5e3Sopenharmony_ciarr.push(reg20.test('abcç2')) 1434514f5e3Sopenharmony_ciarr.push(reg20.test('3kərə4kərə')) 1444514f5e3Sopenharmony_ci 1454514f5e3Sopenharmony_cilet reg21 = /^[0-9А-Я]+$/i 1464514f5e3Sopenharmony_ciarr.push(reg21.test('абв1')) 1474514f5e3Sopenharmony_ciarr.push(reg21.test('жаба')) 1484514f5e3Sopenharmony_ciarr.push(reg21.test('яГоДа2')) 1494514f5e3Sopenharmony_ciarr.push(reg21.test('йЮя')) 1504514f5e3Sopenharmony_ci 1514514f5e3Sopenharmony_cilet reg22 = /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i 1524514f5e3Sopenharmony_ciarr.push(reg22.test('řiť123')) 1534514f5e3Sopenharmony_ci 1544514f5e3Sopenharmony_cilet reg23 = /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i 1554514f5e3Sopenharmony_ciarr.push(reg23.test('1môj')) 1564514f5e3Sopenharmony_ciarr.push(reg23.test('2ľúbím')) 1574514f5e3Sopenharmony_ciarr.push(reg23.test('3mäkčeň')) 1584514f5e3Sopenharmony_ciarr.push(reg23.test('5vŕba')) 1594514f5e3Sopenharmony_ciarr.push(reg23.test('6ňorimberk')) 1604514f5e3Sopenharmony_ciarr.push(reg23.test('7ťava')) 1614514f5e3Sopenharmony_ciarr.push(reg23.test('8žanéta')) 1624514f5e3Sopenharmony_ciarr.push(reg23.test('9Ďábelské')) 1634514f5e3Sopenharmony_ciarr.push(reg23.test('10ódy')) 1644514f5e3Sopenharmony_ci 1654514f5e3Sopenharmony_cilet reg24 = /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i 1664514f5e3Sopenharmony_ciarr.push(reg24.test('Kán123')) 1674514f5e3Sopenharmony_ciarr.push(reg24.test('één354')) 1684514f5e3Sopenharmony_ci 1694514f5e3Sopenharmony_cilet reg25 = /^[0-9A-ZÅÄÖ]+$/i 1704514f5e3Sopenharmony_ciarr.push(reg25.test('äiti124')) 1714514f5e3Sopenharmony_ciarr.push(reg25.test('451åå23')) 1724514f5e3Sopenharmony_ci 1734514f5e3Sopenharmony_cilet reg26 = /^[0-9A-ZÄÖÜß]+$/i 1744514f5e3Sopenharmony_ciarr.push(reg26.test('äbc123')) 1754514f5e3Sopenharmony_ci 1764514f5e3Sopenharmony_cilet reg27 = /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i 1774514f5e3Sopenharmony_ciarr.push(reg27.test('0árvíztűrőtükörfúrógép123')) 1784514f5e3Sopenharmony_ci 1794514f5e3Sopenharmony_cilet reg28 = /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i 1804514f5e3Sopenharmony_ciarr.push(reg28.test('palíndromo')) 1814514f5e3Sopenharmony_ciarr.push(reg28.test('2órgão')) 1824514f5e3Sopenharmony_ciarr.push(reg28.test('qwértyúão9')) 1834514f5e3Sopenharmony_ciarr.push(reg28.test('àäãcë4üïÄÏÜ')) 1844514f5e3Sopenharmony_ci 1854514f5e3Sopenharmony_cilet reg29 = /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i 1864514f5e3Sopenharmony_ciarr.push(reg29.test('123àéèìîóòù')) 1874514f5e3Sopenharmony_ciarr.push(reg29.test('met23ró')) 1884514f5e3Sopenharmony_ciarr.push(reg29.test('pès56ca')) 1894514f5e3Sopenharmony_ciarr.push(reg29.test('gen45î')) 1904514f5e3Sopenharmony_ci 1914514f5e3Sopenharmony_cilet reg30 = /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i 1924514f5e3Sopenharmony_ciarr.push(reg30.test('ábcó123')) 1934514f5e3Sopenharmony_ci 1944514f5e3Sopenharmony_cilet reg31 = /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i 1954514f5e3Sopenharmony_ciarr.push(reg31.test('Thầy3')) 1964514f5e3Sopenharmony_ciarr.push(reg31.test('3Gà')) 1974514f5e3Sopenharmony_ci 1984514f5e3Sopenharmony_cilet reg32 = /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i 1994514f5e3Sopenharmony_ciarr.push(reg32.test('kre123ską')) 2004514f5e3Sopenharmony_ciarr.push(reg32.test('zam21knięte')) 2014514f5e3Sopenharmony_ciarr.push(reg32.test('zw23ykłe')) 2024514f5e3Sopenharmony_ciarr.push(reg32.test('prz23yjęły')) 2034514f5e3Sopenharmony_ciarr.push(reg32.test('świ23ęty')) 2044514f5e3Sopenharmony_ciarr.push(reg32.test('Poz1322wól')) 2054514f5e3Sopenharmony_ci 2064514f5e3Sopenharmony_cilet reg33 = /^[0-9А-ЯЂЈЉЊЋЏ]+$/i 2074514f5e3Sopenharmony_ciarr.push(reg33.test('ШћжЂљЕ123')) 2084514f5e3Sopenharmony_ci 2094514f5e3Sopenharmony_cilet reg34 = /^[0-9A-ZČĆŽŠĐ]+$/i 2104514f5e3Sopenharmony_ciarr.push(reg34.test('ŠAabčšđćž123')) 2114514f5e3Sopenharmony_ciarr.push(reg34.test('ŠATRO11Ćčđš')) 2124514f5e3Sopenharmony_ci 2134514f5e3Sopenharmony_cilet reg35 = /^[0-9A-ZÅÄÖ]+$/i 2144514f5e3Sopenharmony_ciarr.push(reg35.test('religiös13')) 2154514f5e3Sopenharmony_ciarr.push(reg35.test('st23jäla')) 2164514f5e3Sopenharmony_ciarr.push(reg35.test('västgöte123')) 2174514f5e3Sopenharmony_ci 2184514f5e3Sopenharmony_cilet reg36 = /^[0-9A-ZÇĞİıÖŞÜ]+$/i 2194514f5e3Sopenharmony_ciarr.push(reg36.test('AİıÖöÇ窺ĞğÜüZ123')) 2204514f5e3Sopenharmony_ci 2214514f5e3Sopenharmony_cilet reg37 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$") 2224514f5e3Sopenharmony_ciarr.push(reg37.test('0٫0000000000001')) 2234514f5e3Sopenharmony_ci 2244514f5e3Sopenharmony_cilet reg38 = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\٫[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$") 2254514f5e3Sopenharmony_ciarr.push(reg38.test('123٫')) 2264514f5e3Sopenharmony_ciarr.push(reg38.test('123٫123')) 2274514f5e3Sopenharmony_ciarr.push(reg38.test('-123٫123')) 2284514f5e3Sopenharmony_ci 2294514f5e3Sopenharmony_cilet reg39 =/^[A-Z0-9_\-]*$/i 2304514f5e3Sopenharmony_ciarr.push(reg39.test('')) 2314514f5e3Sopenharmony_ci 2324514f5e3Sopenharmony_cilet reg40 = RegExp("^(?!-? )(?=.*\\d)(\\¥)?-?(0|[1-9]\\d|[1-9]\\d{0,2}(\\,\\d{3})*)?(\\.(\\d{2}))?$") 2334514f5e3Sopenharmony_ciarr.push(reg40.test('¥6,954,231')) 2344514f5e3Sopenharmony_ciarr.push(reg40.test('¥-6,954,231')) 2354514f5e3Sopenharmony_ci 2364514f5e3Sopenharmony_civar reg41 = /^[A-VXYZÇƏĞİıÖŞÜ]+$/i; 2374514f5e3Sopenharmony_ciarr.push(reg41.test('Azərbaycan')) 2384514f5e3Sopenharmony_ciarr.push(reg41.test('üöğıəçş')) 2394514f5e3Sopenharmony_ciarr.push(reg41.test('sizAzərbaycanlaşdırılmışlardansınızmı')) 2404514f5e3Sopenharmony_ciarr.push(reg41.test('dahaBirDüzgünString')) 2414514f5e3Sopenharmony_ciarr.push(reg41.test('abcçdeəfgğhxıijkqlmnoöprsştuüvyz')) 2424514f5e3Sopenharmony_ci 2434514f5e3Sopenharmony_cilet reg42 = /^[А-Я]+$/i 2444514f5e3Sopenharmony_ciarr.push(reg42.test('абв')) 2454514f5e3Sopenharmony_ciarr.push(reg42.test('жаба')) 2464514f5e3Sopenharmony_ciarr.push(reg42.test('яГоДа')) 2474514f5e3Sopenharmony_ci 2484514f5e3Sopenharmony_cilet reg43 = /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i 2494514f5e3Sopenharmony_ciarr.push(reg43.test('žluťoučký')) 2504514f5e3Sopenharmony_ciarr.push(reg43.test('Pěl')) 2514514f5e3Sopenharmony_ciarr.push(reg43.test('Ďábelské')) 2524514f5e3Sopenharmony_ciarr.push(reg43.test('ódy')) 2534514f5e3Sopenharmony_ci 2544514f5e3Sopenharmony_cilet reg44 = /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i 2554514f5e3Sopenharmony_ciarr.push(reg44.test('môj')) 2564514f5e3Sopenharmony_ciarr.push(reg44.test('ľúbím')) 2574514f5e3Sopenharmony_ciarr.push(reg44.test('mäkčeň')) 2584514f5e3Sopenharmony_ciarr.push(reg44.test('vŕba')) 2594514f5e3Sopenharmony_ciarr.push(reg44.test('ňorimberk')) 2604514f5e3Sopenharmony_ci 2614514f5e3Sopenharmony_cilet reg45 = /^[A-ZÆØÅ]+$/i 2624514f5e3Sopenharmony_ciarr.push(reg45.test('aøå')) 2634514f5e3Sopenharmony_ci 2644514f5e3Sopenharmony_cilet reg46 = /^[A-ZÁÉËÏÓÖÜÚ]+$/i 2654514f5e3Sopenharmony_ciarr.push(reg46.test('Kán')) 2664514f5e3Sopenharmony_ciarr.push(reg46.test('één')) 2674514f5e3Sopenharmony_ciarr.push(reg46.test('vóór')) 2684514f5e3Sopenharmony_ciarr.push(reg46.test('nú')) 2694514f5e3Sopenharmony_ciarr.push(reg46.test('héél')) 2704514f5e3Sopenharmony_ci 2714514f5e3Sopenharmony_cilet reg47 = /^[A-ZÄÖÜß]+$/i 2724514f5e3Sopenharmony_ciarr.push(reg47.test('äbc')) 2734514f5e3Sopenharmony_ciarr.push(reg47.test('FöÖbär')) 2744514f5e3Sopenharmony_ci 2754514f5e3Sopenharmony_cilet reg48 = /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i 2764514f5e3Sopenharmony_ciarr.push(reg48.test('árvíztűrőtükörfúrógép')) 2774514f5e3Sopenharmony_ci 2784514f5e3Sopenharmony_ciarr.forEach((item)=>{ 2794514f5e3Sopenharmony_ci if(!item){ 2804514f5e3Sopenharmony_ci temp = false 2814514f5e3Sopenharmony_ci } 2824514f5e3Sopenharmony_ci}) 2834514f5e3Sopenharmony_ciprint(temp) 2844514f5e3Sopenharmony_ci 2854514f5e3Sopenharmony_cilet arr1 = [] 2864514f5e3Sopenharmony_cilet temp1 = false 2874514f5e3Sopenharmony_cilet reg49 = /[^A-Z0-9+\/=]/i; 2884514f5e3Sopenharmony_ciarr1.push(reg49.test("Zg==")); 2894514f5e3Sopenharmony_ciarr1.push(reg49.test("Zm8=")); 2904514f5e3Sopenharmony_ciarr1.push(reg49.test("Zm9v")); 2914514f5e3Sopenharmony_ciarr1.push(reg49.test("Zm9vYg==")); 2924514f5e3Sopenharmony_ciarr1.push(reg49.test("Zm9vYmE=")); 2934514f5e3Sopenharmony_ciarr1.push(reg49.test("Zm9vYmFy")); 2944514f5e3Sopenharmony_ciarr1.push(reg49.test( 2954514f5e3Sopenharmony_ci "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4=" 2964514f5e3Sopenharmony_ci)); 2974514f5e3Sopenharmony_ciarr1.push(reg49.test("Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==")); 2984514f5e3Sopenharmony_ciarr1.push(reg49.test("U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==")); 2994514f5e3Sopenharmony_ciarr1.forEach((item)=>{ 3004514f5e3Sopenharmony_ci if(item){ 3014514f5e3Sopenharmony_ci temp1 = true 3024514f5e3Sopenharmony_ci } 3034514f5e3Sopenharmony_ci}) 3044514f5e3Sopenharmony_ciprint(temp1) 3054514f5e3Sopenharmony_cilet str1 = 'SC52BAHL01031234567890123456USD' 3064514f5e3Sopenharmony_ciprint(str1.replace(/[^A-Z0-9]+/gi, '')) 3074514f5e3Sopenharmony_ci 3084514f5e3Sopenharmony_cilet reg50 = /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i 3094514f5e3Sopenharmony_ci 3104514f5e3Sopenharmony_cilet regabc = /abc/g; 3114514f5e3Sopenharmony_cilet strabcd = "abcdabcdabcd"; 3124514f5e3Sopenharmony_cifor (let i = 0; i < 10; i++) { 3134514f5e3Sopenharmony_ci // cache is used in this case 3144514f5e3Sopenharmony_ci print(regabc.test(strabcd)); 3154514f5e3Sopenharmony_ci} 3164514f5e3Sopenharmony_ci 3174514f5e3Sopenharmony_cilet str2 = "aaaabbBbcccC"; 3184514f5e3Sopenharmony_cifor (let i = 0; i < 2; i++) { 3194514f5e3Sopenharmony_ci print(str2); 3204514f5e3Sopenharmony_ci let t1 = str2.replace(/([A-Z])/g, function(e) { 3214514f5e3Sopenharmony_ci return "_" + e; 3224514f5e3Sopenharmony_ci }); 3234514f5e3Sopenharmony_ci print(t1); 3244514f5e3Sopenharmony_ci let t2 = str2.replace(/([A-Z])/g, "_$1"); 3254514f5e3Sopenharmony_ci print(t2); 3264514f5e3Sopenharmony_ci print(t1.replace(/([a-z]+)/g, "_xy")); 3274514f5e3Sopenharmony_ci print(t2.replace(/_/g, "")); 3284514f5e3Sopenharmony_ci} 3294514f5e3Sopenharmony_ci 3304514f5e3Sopenharmony_ci// regexp cache test 3314514f5e3Sopenharmony_cilet mediaReg = "\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)"; 3324514f5e3Sopenharmony_cilet string = '(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s'; 3334514f5e3Sopenharmony_ciconst regex1 = new RegExp(mediaReg); 3344514f5e3Sopenharmony_cilet matchArray = string.match(regex1); 3354514f5e3Sopenharmony_ciprint(matchArray); 3364514f5e3Sopenharmony_ci 3374514f5e3Sopenharmony_ci// Test regexp.test fastpath 3384514f5e3Sopenharmony_civar protoExec = RegExp.prototype.exec 3394514f5e3Sopenharmony_ciRegExp.prototype.exec = function () { 3404514f5e3Sopenharmony_ci return null 3414514f5e3Sopenharmony_ci} 3424514f5e3Sopenharmony_civar reg = /a/ 3434514f5e3Sopenharmony_ciprint(reg.test("aaaaa")); 3444514f5e3Sopenharmony_ci 3454514f5e3Sopenharmony_cidelete RegExp.prototype.exec 3464514f5e3Sopenharmony_ciprint(reg.test("aaaaa")); 3474514f5e3Sopenharmony_ci 3484514f5e3Sopenharmony_ciObject.prototype.exec = function () { 3494514f5e3Sopenharmony_ci return null 3504514f5e3Sopenharmony_ci} 3514514f5e3Sopenharmony_ciprint(reg.test("aaaaa")); 3524514f5e3Sopenharmony_ci 3534514f5e3Sopenharmony_cidelete Object.prototype.exec 3544514f5e3Sopenharmony_ciRegExp.prototype.exec = protoExec 3554514f5e3Sopenharmony_ciprint(reg.test("aaaaa")); 3564514f5e3Sopenharmony_ci 3574514f5e3Sopenharmony_civar protoTest = RegExp.prototype.test 3584514f5e3Sopenharmony_ciRegExp.prototype.test = function () { 3594514f5e3Sopenharmony_ci return false 3604514f5e3Sopenharmony_ci} 3614514f5e3Sopenharmony_civar reg2 = /foo*/ 3624514f5e3Sopenharmony_ciprint(reg2.test("fooooooo")); 3634514f5e3Sopenharmony_ci 3644514f5e3Sopenharmony_ciRegExp.prototype.test = protoTest 3654514f5e3Sopenharmony_ciprint(reg2.test("fooooooo")); 3664514f5e3Sopenharmony_ci 3674514f5e3Sopenharmony_ci// Same hash in cached result, but different flags. 3684514f5e3Sopenharmony_civar regexp1 = /a*/gs; 3694514f5e3Sopenharmony_civar regexp2 = /a*/g; 3704514f5e3Sopenharmony_ciregexp2.lastIndex = 8; 3714514f5e3Sopenharmony_ciprint(regexp1.exec('aaa')); 3724514f5e3Sopenharmony_ciprint(regexp2.exec('aaa')); 3734514f5e3Sopenharmony_ci 3744514f5e3Sopenharmony_ci// Same hash in cached result, and same flags, but different lastIndex. 3754514f5e3Sopenharmony_civar regexp3 = /a*/g; 3764514f5e3Sopenharmony_civar regexp4 = /a*/g; 3774514f5e3Sopenharmony_ciregexp4.lastIndex = 1; 3784514f5e3Sopenharmony_ciprint(regexp3.exec('aaabab')); 3794514f5e3Sopenharmony_ciprint(regexp4.exec('aaabaa')); 3804514f5e3Sopenharmony_ci 3814514f5e3Sopenharmony_ciconst v43 = /V[\d-\d]/ys; 3824514f5e3Sopenharmony_ciconst o54 = { 3834514f5e3Sopenharmony_ci __proto__: v43, 3844514f5e3Sopenharmony_ci}; 3854514f5e3Sopenharmony_citry { 3864514f5e3Sopenharmony_ci o54.test(Map); 3874514f5e3Sopenharmony_ci} catch (e) { 3884514f5e3Sopenharmony_ci print(e) 3894514f5e3Sopenharmony_ci} 3904514f5e3Sopenharmony_ci 3914514f5e3Sopenharmony_ci// Testing regexp.prototype.replace after optimization 3924514f5e3Sopenharmony_ci{ 3934514f5e3Sopenharmony_ci const re1 = /[Cz]/; 3944514f5e3Sopenharmony_ci const re2 = /[Cz]/g; 3954514f5e3Sopenharmony_ci const re3 = /([Cz])/; 3964514f5e3Sopenharmony_ci const re4 = /([Cz])/g; 3974514f5e3Sopenharmony_ci 3984514f5e3Sopenharmony_ci let replace_str = "abCdefgzabCdefgzabCdefgz"; 3994514f5e3Sopenharmony_ci let replace_result = replace_str.replace(re1, ""); 4004514f5e3Sopenharmony_ci print(re1.lastIndex); 4014514f5e3Sopenharmony_ci let cached_reuslt = replace_str.replace(re1, ""); 4024514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 4034514f5e3Sopenharmony_ci print(re1.lastIndex); 4044514f5e3Sopenharmony_ci 4054514f5e3Sopenharmony_ci replace_result = replace_str.replace(re2, "xyz"); 4064514f5e3Sopenharmony_ci print(re2.lastIndex); 4074514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re2, "xyz"); 4084514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 4094514f5e3Sopenharmony_ci print(re2.lastIndex); 4104514f5e3Sopenharmony_ci 4114514f5e3Sopenharmony_ci replace_result = replace_str.replace(re3, "x$1yz"); 4124514f5e3Sopenharmony_ci print(re3.lastIndex); 4134514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re3, "x$1yz"); 4144514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 4154514f5e3Sopenharmony_ci print(re3.lastIndex); 4164514f5e3Sopenharmony_ci 4174514f5e3Sopenharmony_ci replace_result = replace_str.replace(re4, String); 4184514f5e3Sopenharmony_ci print(re4.lastIndex); 4194514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re4, String); 4204514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 4214514f5e3Sopenharmony_ci print(re4.lastIndex); 4224514f5e3Sopenharmony_ci} 4234514f5e3Sopenharmony_ci 4244514f5e3Sopenharmony_ci// test RegExp.prototype.xx 4254514f5e3Sopenharmony_ciprint(RegExp.prototype.dotAll) 4264514f5e3Sopenharmony_ciprint(RegExp.prototype.global) 4274514f5e3Sopenharmony_ciprint(RegExp.prototype.hasIndices) 4284514f5e3Sopenharmony_ciprint(RegExp.prototype.ignoreCase) 4294514f5e3Sopenharmony_ciprint(RegExp.prototype.multiline) 4304514f5e3Sopenharmony_ciprint(RegExp.prototype.sticky) 4314514f5e3Sopenharmony_ciprint(RegExp.prototype.unicode) 4324514f5e3Sopenharmony_ciprint(RegExp.prototype.lastIndex) 4334514f5e3Sopenharmony_ciprint(RegExp.prototype.flags) 4344514f5e3Sopenharmony_ciprint(RegExp.prototype.source) 4354514f5e3Sopenharmony_citry { 4364514f5e3Sopenharmony_ci RegExp.prototype.test("abc") 4374514f5e3Sopenharmony_ci} catch (e) { 4384514f5e3Sopenharmony_ci print(e.name) 4394514f5e3Sopenharmony_ci} 4404514f5e3Sopenharmony_citry { 4414514f5e3Sopenharmony_ci RegExp.prototype.exec("abc") 4424514f5e3Sopenharmony_ci} catch (e) { 4434514f5e3Sopenharmony_ci print(e.name) 4444514f5e3Sopenharmony_ci} 4454514f5e3Sopenharmony_ciprint(RegExp.prototype.toString()) 4464514f5e3Sopenharmony_ci 4474514f5e3Sopenharmony_cilet inputString = "/vedio/av{avid}{cid}"; 4484514f5e3Sopenharmony_cilet extractedContent = inputString.match(/\{([^{}]+)\}/g); 4494514f5e3Sopenharmony_cilet replacedString = inputString.replace(/\{([^{}]+)\}/g, '(uuu)').replace(/\//g, "\\/"); 4504514f5e3Sopenharmony_ciprint(replacedString); 4514514f5e3Sopenharmony_ci 4524514f5e3Sopenharmony_cilet str = "beep boop afff测试样本one1"; 4534514f5e3Sopenharmony_ciprint(str.split(/([{}:;,]|\s+)/)); 4544514f5e3Sopenharmony_ci 4554514f5e3Sopenharmony_cifunction verifyRegExp(text) { 4564514f5e3Sopenharmony_ci text = text.replace(new RegExp('[\\s]', 'g'), ' '); 4574514f5e3Sopenharmony_ci let emRegExp = new RegExp('<em>.*?</em>', 'ig'); 4584514f5e3Sopenharmony_ci let results = text.split(emRegExp); 4594514f5e3Sopenharmony_ci text.match(emRegExp); 4604514f5e3Sopenharmony_ci return results; 4614514f5e3Sopenharmony_ci} 4624514f5e3Sopenharmony_ci 4634514f5e3Sopenharmony_ciconst srcTextA = '<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz' 4644514f5e3Sopenharmony_ciconst srcTextAbcd = '<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz' 4654514f5e3Sopenharmony_ci 4664514f5e3Sopenharmony_ciprint(`verifyRegExp_1: ${verifyRegExp(srcTextA)}`); 4674514f5e3Sopenharmony_ciprint(`verifyRegExp_2: ${verifyRegExp(srcTextAbcd)}`); 4684514f5e3Sopenharmony_ciprint(`verifyRegExp_3: ${verifyRegExp(srcTextAbcd)}`); 4694514f5e3Sopenharmony_ci 4704514f5e3Sopenharmony_ci//regexp unicode property 4714514f5e3Sopenharmony_ciconst ans1 = /\p{Alphabetic}/u.test("æ"); 4724514f5e3Sopenharmony_ciconst ans2 = /\p{Alpha}/u.test("2"); 4734514f5e3Sopenharmony_ciconst ans3 = /^[\p{Lu}\p{Ll}]+$/u.test("ASDFasdf"); 4744514f5e3Sopenharmony_ciconst ans4 = /^[\P{Lu}\p{Ll}]+$/u.test("ASDFasdf"); 4754514f5e3Sopenharmony_ciconst ans5 = /\P{Ll}/iu.test("b"); 4764514f5e3Sopenharmony_ciconst ans6 = /\p{Ll}/iu.test("b"); 4774514f5e3Sopenharmony_ciconst ans7 = /[^\P{Any}]+/u.test(456); 4784514f5e3Sopenharmony_ciconst ans8 = /\p{Assigned}+/u.test(""); 4794514f5e3Sopenharmony_ciconst ans9 = /[\p{P}\p{S}]/u.test("!"); 4804514f5e3Sopenharmony_ciconst ans10 = /\p{General_Category=Math_Symbol}/u.test("+"); 4814514f5e3Sopenharmony_ciprint(ans1); 4824514f5e3Sopenharmony_ciprint(ans2); 4834514f5e3Sopenharmony_ciprint(ans3); 4844514f5e3Sopenharmony_ciprint(ans4); 4854514f5e3Sopenharmony_ciprint(ans5); 4864514f5e3Sopenharmony_ciprint(ans6); 4874514f5e3Sopenharmony_ciprint(ans7); 4884514f5e3Sopenharmony_ciprint(ans8); 4894514f5e3Sopenharmony_ciprint(ans9); 4904514f5e3Sopenharmony_ciprint(ans10); 4914514f5e3Sopenharmony_citry { 4924514f5e3Sopenharmony_ci const ans11 = RegExp("/[\\p{}]/u"); 4934514f5e3Sopenharmony_ci print(ans11); 4944514f5e3Sopenharmony_ci} catch(e) { 4954514f5e3Sopenharmony_ci print(e); 4964514f5e3Sopenharmony_ci} 4974514f5e3Sopenharmony_ciconst str3 = "a-b-c"; 4984514f5e3Sopenharmony_ciconst re = /-/y; 4994514f5e3Sopenharmony_ciprint(str3.split(re)); 5004514f5e3Sopenharmony_ci 5014514f5e3Sopenharmony_cire.lastIndex = 1; 5024514f5e3Sopenharmony_ciprint(str3.split(re)); 5034514f5e3Sopenharmony_ci 5044514f5e3Sopenharmony_cire.lastIndex = -1; 5054514f5e3Sopenharmony_ciprint(str3.split(re)); 5064514f5e3Sopenharmony_ci 5074514f5e3Sopenharmony_cire.lastIndex = 3; 5084514f5e3Sopenharmony_ciprint(str3.split(re)); 5094514f5e3Sopenharmony_ci 5104514f5e3Sopenharmony_ciprint(re.test(str3)); 5114514f5e3Sopenharmony_ci 5124514f5e3Sopenharmony_ciprint(str3.split(/-/g)); 5134514f5e3Sopenharmony_ci 5144514f5e3Sopenharmony_ci// search 5154514f5e3Sopenharmony_ciconst str4 = "abc"; 5164514f5e3Sopenharmony_cilet re1 = /b/; 5174514f5e3Sopenharmony_cire1.lastIndex = 2; 5184514f5e3Sopenharmony_ciprint(str4.search(re1)); 5194514f5e3Sopenharmony_ciprint(str4.search(/b/y)); 5204514f5e3Sopenharmony_ciprint(str4.search(re1)); 5214514f5e3Sopenharmony_ciprint(re1.lastIndex); 5224514f5e3Sopenharmony_ci 5234514f5e3Sopenharmony_ci// check cache 5244514f5e3Sopenharmony_ciconst str5 = "a-bc"; 5254514f5e3Sopenharmony_cilet re2 = /-/; 5264514f5e3Sopenharmony_cire2.lastIndex = 2; 5274514f5e3Sopenharmony_ciprint(str5.split(re2)); 5284514f5e3Sopenharmony_ciprint(re2.lastIndex); 5294514f5e3Sopenharmony_ciprint(str5.split(re2)); 5304514f5e3Sopenharmony_ciprint(re2.lastIndex); 5314514f5e3Sopenharmony_ci 5324514f5e3Sopenharmony_ciconst str6 = "abcabc"; 5334514f5e3Sopenharmony_cilet re3 = /abc/; 5344514f5e3Sopenharmony_cire3.lastIndex = 2; 5354514f5e3Sopenharmony_ciprint(str6.match(re3)); 5364514f5e3Sopenharmony_ciprint(re3.lastIndex); 5374514f5e3Sopenharmony_ciprint(str6.match(re3)); 5384514f5e3Sopenharmony_ciprint(re3.lastIndex); 5394514f5e3Sopenharmony_ci 5404514f5e3Sopenharmony_cilet re4 = /abc/g; 5414514f5e3Sopenharmony_cire4.lastIndex = 2; 5424514f5e3Sopenharmony_ciprint(str6.match(re4)); 5434514f5e3Sopenharmony_ciprint(re4.lastIndex); 5444514f5e3Sopenharmony_ciprint(str6.match(re4)); 5454514f5e3Sopenharmony_ciprint(re4.lastIndex); 5464514f5e3Sopenharmony_ciObject.defineProperty(RegExp.prototype, "global", { 5474514f5e3Sopenharmony_ci value: true 5484514f5e3Sopenharmony_ci}) 5494514f5e3Sopenharmony_civar flags = RegExp.prototype.flags; 5504514f5e3Sopenharmony_ciObject.defineProperty(RegExp.prototype, "global", { 5514514f5e3Sopenharmony_ci value: false 5524514f5e3Sopenharmony_ci}) 5534514f5e3Sopenharmony_ciprint(flags); 5544514f5e3Sopenharmony_ciprint(str6.match(re4)); 5554514f5e3Sopenharmony_ciprint(re4.lastIndex); 5564514f5e3Sopenharmony_ciprint(str6.match(re4)); 5574514f5e3Sopenharmony_ciprint(re4.lastIndex); 5584514f5e3Sopenharmony_ci 5594514f5e3Sopenharmony_cilet myExp = new RegExp("a+b+c"); 5604514f5e3Sopenharmony_ciObject.defineProperty(myExp, "sticky", { 5614514f5e3Sopenharmony_ci value: true 5624514f5e3Sopenharmony_ci }) 5634514f5e3Sopenharmony_ciprint(myExp.toString()); 5644514f5e3Sopenharmony_ci 5654514f5e3Sopenharmony_ci// Testing regexp.prototype.replace after optimization 5664514f5e3Sopenharmony_ci{ 5674514f5e3Sopenharmony_ci const re1 = /[Cz]/; 5684514f5e3Sopenharmony_ci const re2 = /[Cz]/g; 5694514f5e3Sopenharmony_ci const re3 = /([Cz])/; 5704514f5e3Sopenharmony_ci const re4 = /([Cz])/g; 5714514f5e3Sopenharmony_ci 5724514f5e3Sopenharmony_ci let replace_str = "abCdefgzabCdefgzabCdefgz"; 5734514f5e3Sopenharmony_ci let replace_result = replace_str.replace(re1, ""); 5744514f5e3Sopenharmony_ci print(re1.lastIndex); 5754514f5e3Sopenharmony_ci let cached_reuslt = replace_str.replace(re1, ""); 5764514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 5774514f5e3Sopenharmony_ci print(re1.lastIndex); 5784514f5e3Sopenharmony_ci 5794514f5e3Sopenharmony_ci replace_result = replace_str.replace(re2, "xyz"); 5804514f5e3Sopenharmony_ci print(re2.lastIndex); 5814514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re2, "xyz"); 5824514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 5834514f5e3Sopenharmony_ci print(re2.lastIndex); 5844514f5e3Sopenharmony_ci 5854514f5e3Sopenharmony_ci replace_result = replace_str.replace(re3, "x$1yz"); 5864514f5e3Sopenharmony_ci print(re3.lastIndex); 5874514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re3, "x$1yz"); 5884514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 5894514f5e3Sopenharmony_ci print(re3.lastIndex); 5904514f5e3Sopenharmony_ci 5914514f5e3Sopenharmony_ci replace_result = replace_str.replace(re4, String); 5924514f5e3Sopenharmony_ci print(re4.lastIndex); 5934514f5e3Sopenharmony_ci cached_reuslt = replace_str.replace(re4, String); 5944514f5e3Sopenharmony_ci print(replace_result === cached_reuslt); 5954514f5e3Sopenharmony_ci print(re4.lastIndex); 5964514f5e3Sopenharmony_ci} 5974514f5e3Sopenharmony_ci 5984514f5e3Sopenharmony_ciconst regex = /(?:)+/; 5994514f5e3Sopenharmony_ciconst str10 = "abcabcabc"; 6004514f5e3Sopenharmony_ciconst matches = regex.test(str10); 6014514f5e3Sopenharmony_ciprint(matches); 6024514f5e3Sopenharmony_ciconst matches1 = regex.exec(str10); 6034514f5e3Sopenharmony_ciprint(matches1); 6044514f5e3Sopenharmony_ci 6054514f5e3Sopenharmony_citry { 6064514f5e3Sopenharmony_ci let matchReg = new RegExp("@【哈哈】*^o^*|@小米(kk)",'g'); 6074514f5e3Sopenharmony_ci} catch (error) { 6084514f5e3Sopenharmony_ci print(error) 6094514f5e3Sopenharmony_ci} 6104514f5e3Sopenharmony_ci 6114514f5e3Sopenharmony_cilet e = /./; 6124514f5e3Sopenharmony_cie.exec = function() { 6134514f5e3Sopenharmony_ci return []; 6144514f5e3Sopenharmony_ci} 6154514f5e3Sopenharmony_ci"".replace(e, ""); 6164514f5e3Sopenharmony_cidelete e.exec; 6174514f5e3Sopenharmony_ci 6184514f5e3Sopenharmony_ci{ 6194514f5e3Sopenharmony_ci const v0 = /qeu(?<a>.)\k<a>(x)(x)(x)\1*xyz{93}/ugysd; 6204514f5e3Sopenharmony_ci const v4 = typeof Date === "string"; 6214514f5e3Sopenharmony_ci v0[Symbol.match] = v4; 6224514f5e3Sopenharmony_ci print(v0["exec"]()); 6234514f5e3Sopenharmony_ci} 6244514f5e3Sopenharmony_ci 6254514f5e3Sopenharmony_ci{ 6264514f5e3Sopenharmony_ci ("65535").split(/(?!\1(a\1)\1)\1/g); 6274514f5e3Sopenharmony_ci const o4 = { 6284514f5e3Sopenharmony_ci ...RegExp, 6294514f5e3Sopenharmony_ci }; 6304514f5e3Sopenharmony_ci print(o4); 6314514f5e3Sopenharmony_ci} 6324514f5e3Sopenharmony_ci 6334514f5e3Sopenharmony_ci{ 6344514f5e3Sopenharmony_ci const v2 = /e\8Z(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\10*/misd; 6354514f5e3Sopenharmony_ci v2[1073741824] = -194290175n; 6364514f5e3Sopenharmony_ci for (let v3 = 0; v3 < 2; v3++) { 6374514f5e3Sopenharmony_ci print(v2.test(-194290175n)); 6384514f5e3Sopenharmony_ci } 6394514f5e3Sopenharmony_ci} 6404514f5e3Sopenharmony_ci 6414514f5e3Sopenharmony_cifunction f(...args) { 6424514f5e3Sopenharmony_ci return {}; 6434514f5e3Sopenharmony_ci} 6444514f5e3Sopenharmony_cilet reg51 = new RegExp("a"); 6454514f5e3Sopenharmony_cif.exec = f; 6464514f5e3Sopenharmony_cilet relpfun = reg51[Symbol.replace]; 6474514f5e3Sopenharmony_cirelpfun.apply(f, [1, 2, 3, 4]); 6484514f5e3Sopenharmony_ciprint("success"); 6494514f5e3Sopenharmony_ci 6504514f5e3Sopenharmony_ci{ 6514514f5e3Sopenharmony_ci let str = /^\s*([^;\s]*)/; 6524514f5e3Sopenharmony_ci str.test("text/html"); 6534514f5e3Sopenharmony_ci print(RegExp.$1); 6544514f5e3Sopenharmony_ci str.test("text/plain"); 6554514f5e3Sopenharmony_ci print(RegExp.$1); 6564514f5e3Sopenharmony_ci str.test("text/html"); 6574514f5e3Sopenharmony_ci print(RegExp.$1); 6584514f5e3Sopenharmony_ci} 6594514f5e3Sopenharmony_ci 6604514f5e3Sopenharmony_ci{ 6614514f5e3Sopenharmony_ci let reg52 = /abc/; 6624514f5e3Sopenharmony_ci let count = 0; 6634514f5e3Sopenharmony_ci print(reg52.ignoreCase); 6644514f5e3Sopenharmony_ci print(reg52.global); 6654514f5e3Sopenharmony_ci print(reg52.flags); 6664514f5e3Sopenharmony_ci Object.defineProperty(reg52, "global", { 6674514f5e3Sopenharmony_ci get: function() { count++; return true; } 6684514f5e3Sopenharmony_ci }); 6694514f5e3Sopenharmony_ci Object.defineProperty(reg52, "ignoreCase", { 6704514f5e3Sopenharmony_ci get: function() { count++; return true; } 6714514f5e3Sopenharmony_ci }); 6724514f5e3Sopenharmony_ci 6734514f5e3Sopenharmony_ci print(reg52.ignoreCase); 6744514f5e3Sopenharmony_ci print(count); 6754514f5e3Sopenharmony_ci print(reg52.global); 6764514f5e3Sopenharmony_ci print(count); 6774514f5e3Sopenharmony_ci print(reg52.flags); 6784514f5e3Sopenharmony_ci print(count); 6794514f5e3Sopenharmony_ci} 6804514f5e3Sopenharmony_ci 6814514f5e3Sopenharmony_ci// The above test case in false environment did not reset the environment 6824514f5e3Sopenharmony_ciObject.defineProperty(RegExp.prototype, "global", { 6834514f5e3Sopenharmony_ci value: true 6844514f5e3Sopenharmony_ci}) 6854514f5e3Sopenharmony_cistring = 'aaa\n789\r\nccc\r\n345'; 6864514f5e3Sopenharmony_civar pattern = /\d$/gm; 6874514f5e3Sopenharmony_ciresult = string.match(pattern); 6884514f5e3Sopenharmony_ciprint(2 == result.length); 6894514f5e3Sopenharmony_ciprint('9' == result[0]); 6904514f5e3Sopenharmony_ciprint('5' == result[1]); 6914514f5e3Sopenharmony_ci 6924514f5e3Sopenharmony_cistring = 'aaa\n789\r\nccc\r\nddd'; 6934514f5e3Sopenharmony_cipattern = /\d$/gm; 6944514f5e3Sopenharmony_ciresult = string.match(pattern); 6954514f5e3Sopenharmony_ciprint(1 == result.length); 6964514f5e3Sopenharmony_ciprint('9' == result[0]); 6974514f5e3Sopenharmony_ci 6984514f5e3Sopenharmony_ci// test getFlags 6994514f5e3Sopenharmony_ciObject.defineProperty(RegExp.prototype, "global", { 7004514f5e3Sopenharmony_ci value: true 7014514f5e3Sopenharmony_ci}) 7024514f5e3Sopenharmony_ciconst res = /abc/giymsud; 7034514f5e3Sopenharmony_cires.lastIndex = -1; 7044514f5e3Sopenharmony_ciprint(res.flags); 7054514f5e3Sopenharmony_ciconst res1 = /abc/g; 7064514f5e3Sopenharmony_cires1.lastIndex = -1; 7074514f5e3Sopenharmony_ciprint(res1.flags); 7084514f5e3Sopenharmony_ciconst res2 = /abc/i; 7094514f5e3Sopenharmony_cires2.lastIndex = -1; 7104514f5e3Sopenharmony_ciprint(res2.flags); 7114514f5e3Sopenharmony_ciconst res3 = /abc/y; 7124514f5e3Sopenharmony_cires3.lastIndex = -1; 7134514f5e3Sopenharmony_ciprint(res3.flags); 7144514f5e3Sopenharmony_ciconst res4 = /abc/m; 7154514f5e3Sopenharmony_cires4.lastIndex = -1; 7164514f5e3Sopenharmony_ciprint(res4.flags); 7174514f5e3Sopenharmony_ciconst res5 = /abc/s; 7184514f5e3Sopenharmony_cires5.lastIndex = -1; 7194514f5e3Sopenharmony_ciprint(res5.flags); 7204514f5e3Sopenharmony_ciconst res6 = /abc/u; 7214514f5e3Sopenharmony_cires6.lastIndex = -1; 7224514f5e3Sopenharmony_ciprint(res6.flags); 7234514f5e3Sopenharmony_ciconst res7 = /abc/d; 7244514f5e3Sopenharmony_cires7.lastIndex = -1; 7254514f5e3Sopenharmony_ciprint(res7.flags); 7264514f5e3Sopenharmony_ciconst res8 = /abc/; 7274514f5e3Sopenharmony_cires8.lastIndex = -1; 7284514f5e3Sopenharmony_ciprint(res8.flags); 729