• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:regexp
18 * @tc.desc:test Regexp
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22{
23  let str = "��";
24  let regexp = /[��]/;
25  print(JSON.stringify(str.replace(regexp,"b")));
26}
27{
28  let str = "��";
29  let regexp = /[��]/g;
30  print(JSON.stringify(str.replace(regexp,"b")));
31}
32{
33  let str = "��";
34  let regexp = /[��]/u;
35  print(JSON.stringify(str.replace(regexp,"b")));
36}
37{
38  let str = "��";
39  let regexp = /[\��]/;
40  print(JSON.stringify(str.replace(regexp,"b")));
41}
42
43
44var reg = /[\x5d-\x7e]/i;
45var result = reg.test("a");
46print(result);
47
48var reg1 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$");
49var result1 = reg1.test('0٫0000000000001');
50print(result1);
51
52var reg2 = /^[Α-ώ]+$/i
53print(reg2.test('άέήίΰϊϋόύώ'));
54
55print(reg2.test('ΆΈΉΊΪΫΎΏ'));
56
57print(reg2.test('αβγδεζηθικλμνξοπρςστυφχψω'));
58
59print(reg2.test('ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'));
60
61let reg3 =/^[A-Z0-9_\-]*$/i
62print(reg3.test(''))
63
64let reg4 =   new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>https?[::]//[^/]+/svn(?:/[a-z0-9.,;?'*:+&%$#=~_ \\u4E00-\\u9FA5-]*)*).*$", "i")
65print(reg4.test('a'));
66
67let 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")
68print(reg5.test('a'));
69
70let reg6 =   new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>(?:ht|f)tps?[::]//(?:[a-z0-9-]+\\.)*[a-z0-9-]+(?:/[a-z0-9]+)*[/a-z0-9.,;?'\\|*:\\\\+&%$#=~_-]*).*$", "i")
71print(reg6.test('a'));
72
73let 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")
74print(reg7.test('a'));
75
76let arr = []
77let temp = true
78var 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;
79arr.push(quotedEmailUserUtf8.test(" foo m端ller "))
80
81let reg8 = /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i
82arr.push(reg8.test('palíndromo'))
83arr.push(reg8.test('órgão'))
84arr.push(reg8.test('qwértyúão'))
85arr.push(reg8.test('àäãcëüïÄÏÜ'))
86
87let reg9 = /^[A-ZÀÉÈÌÎÓÒÙ]+$/i
88arr.push(reg9.test('àéèìîóòù'))
89arr.push(reg9.test('metró'))
90arr.push(reg9.test('pèsca'))
91arr.push(reg9.test('genî'))
92
93let reg10 = /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i
94arr.push(reg10.test('thiến'))
95arr.push(reg10.test('nghiêng'))
96arr.push(reg10.test('chào'))
97arr.push(reg10.test('thế'))
98arr.push(reg10.test('giới'))
99
100let reg11 = /^[A-ZÅÄÖ]+$/i
101arr.push(reg11.test('äiti'))
102
103let reg12 = /^[A-ZÆØÅ]+$/i
104arr.push(reg12.test('aøå'))
105
106let reg13 = /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i
107arr.push(reg13.test('kreską'))
108arr.push(reg13.test('zamknięte'))
109arr.push(reg13.test('zwykłe'))
110arr.push(reg13.test('kropką'))
111arr.push(reg13.test('przyjęły'))
112arr.push(reg13.test('święty'))
113arr.push(reg13.test('Pozwól'))
114
115let reg14 = /^[А-ЯЂЈЉЊЋЏ]+$/i
116arr.push(reg14.test('ШћжЂљЕ'))
117
118let reg15 = /^[A-ZČĆŽŠĐ]+$/i
119arr.push(reg15.test('ŠAabčšđćž'))
120arr.push(reg15.test('ŠATROĆčđš'))
121
122let reg16 = /^[A-ZÁÉÍÑÓÚÜ]+$/i
123arr.push(reg16.test('ábcó'))
124arr.push(reg16.test('dormís'))
125arr.push(reg16.test('volvés'))
126arr.push(reg16.test('español'))
127
128let reg17 = /^[A-ZÅÄÖ]+$/i
129arr.push(reg17.test('religiös'))
130arr.push(reg17.test('stjäla'))
131arr.push(reg17.test('västgöte'))
132
133let reg18 = /^[A-ZÇĞİıÖŞÜ]+$/i
134arr.push(reg18.test('AİıÖöÇ窺ĞğÜüZ'))
135
136let reg19 = /^[Α-ώ]+$/i
137arr.push(reg19.test('άέήίΰϊϋόύώ'))
138arr.push(reg19.test('ΆΈΉΊΪΫΎΏ'))
139
140let reg20 = /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i
141arr.push(reg20.test('Azərbaycan'))
142arr.push(reg20.test('abcç2'))
143arr.push(reg20.test('3kərə4kərə'))
144
145let reg21 = /^[0-9А-Я]+$/i
146arr.push(reg21.test('абв1'))
147arr.push(reg21.test('жаба'))
148arr.push(reg21.test('яГоДа2'))
149arr.push(reg21.test('йЮя'))
150
151let reg22 = /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i
152arr.push(reg22.test('řiť123'))
153
154let reg23 = /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i
155arr.push(reg23.test('1môj'))
156arr.push(reg23.test('2ľúbím'))
157arr.push(reg23.test('3mäkčeň'))
158arr.push(reg23.test('5vŕba'))
159arr.push(reg23.test('6ňorimberk'))
160arr.push(reg23.test('7ťava'))
161arr.push(reg23.test('8žanéta'))
162arr.push(reg23.test('9Ďábelské'))
163arr.push(reg23.test('10ódy'))
164
165let reg24 = /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i
166arr.push(reg24.test('Kán123'))
167arr.push(reg24.test('één354'))
168
169let reg25 = /^[0-9A-ZÅÄÖ]+$/i
170arr.push(reg25.test('äiti124'))
171arr.push(reg25.test('451åå23'))
172
173let reg26 = /^[0-9A-ZÄÖÜß]+$/i
174arr.push(reg26.test('äbc123'))
175
176let reg27 = /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i
177arr.push(reg27.test('0árvíztűrőtükörfúrógép123'))
178
179let reg28 = /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i
180arr.push(reg28.test('palíndromo'))
181arr.push(reg28.test('2órgão'))
182arr.push(reg28.test('qwértyúão9'))
183arr.push(reg28.test('àäãcë4üïÄÏÜ'))
184
185let reg29 = /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i
186arr.push(reg29.test('123àéèìîóòù'))
187arr.push(reg29.test('met23ró'))
188arr.push(reg29.test('pès56ca'))
189arr.push(reg29.test('gen45î'))
190
191let reg30 = /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i
192arr.push(reg30.test('ábcó123'))
193
194let reg31 = /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i
195arr.push(reg31.test('Thầy3'))
196arr.push(reg31.test('3Gà'))
197
198let reg32 = /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i
199arr.push(reg32.test('kre123ską'))
200arr.push(reg32.test('zam21knięte'))
201arr.push(reg32.test('zw23ykłe'))
202arr.push(reg32.test('prz23yjęły'))
203arr.push(reg32.test('świ23ęty'))
204arr.push(reg32.test('Poz1322wól'))
205
206let reg33 = /^[0-9А-ЯЂЈЉЊЋЏ]+$/i
207arr.push(reg33.test('ШћжЂљЕ123'))
208
209let reg34 = /^[0-9A-ZČĆŽŠĐ]+$/i
210arr.push(reg34.test('ŠAabčšđćž123'))
211arr.push(reg34.test('ŠATRO11Ćčđš'))
212
213let reg35 = /^[0-9A-ZÅÄÖ]+$/i
214arr.push(reg35.test('religiös13'))
215arr.push(reg35.test('st23jäla'))
216arr.push(reg35.test('västgöte123'))
217
218let reg36 = /^[0-9A-ZÇĞİıÖŞÜ]+$/i
219arr.push(reg36.test('AİıÖöÇ窺ĞğÜüZ123'))
220
221let reg37 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$")
222arr.push(reg37.test('0٫0000000000001'))
223
224let reg38 = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\٫[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")
225arr.push(reg38.test('123٫'))
226arr.push(reg38.test('123٫123'))
227arr.push(reg38.test('-123٫123'))
228
229let reg39 =/^[A-Z0-9_\-]*$/i
230arr.push(reg39.test(''))
231
232let reg40 = RegExp("^(?!-? )(?=.*\\d)(\\¥)?-?(0|[1-9]\\d|[1-9]\\d{0,2}(\\,\\d{3})*)?(\\.(\\d{2}))?$")
233arr.push(reg40.test('¥6,954,231'))
234arr.push(reg40.test('¥-6,954,231'))
235
236var reg41 = /^[A-VXYZÇƏĞİıÖŞÜ]+$/i;
237arr.push(reg41.test('Azərbaycan'))
238arr.push(reg41.test('üöğıəçş'))
239arr.push(reg41.test('sizAzərbaycanlaşdırılmışlardansınızmı'))
240arr.push(reg41.test('dahaBirDüzgünString'))
241arr.push(reg41.test('abcçdeəfgğhxıijkqlmnoöprsştuüvyz'))
242
243let reg42 = /^[А-Я]+$/i
244arr.push(reg42.test('абв'))
245arr.push(reg42.test('жаба'))
246arr.push(reg42.test('яГоДа'))
247
248let reg43 = /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i
249arr.push(reg43.test('žluťoučký'))
250arr.push(reg43.test('Pěl'))
251arr.push(reg43.test('Ďábelské'))
252arr.push(reg43.test('ódy'))
253
254let reg44 = /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i
255arr.push(reg44.test('môj'))
256arr.push(reg44.test('ľúbím'))
257arr.push(reg44.test('mäkčeň'))
258arr.push(reg44.test('vŕba'))
259arr.push(reg44.test('ňorimberk'))
260
261let reg45 = /^[A-ZÆØÅ]+$/i
262arr.push(reg45.test('aøå'))
263
264let reg46 = /^[A-ZÁÉËÏÓÖÜÚ]+$/i
265arr.push(reg46.test('Kán'))
266arr.push(reg46.test('één'))
267arr.push(reg46.test('vóór'))
268arr.push(reg46.test('nú'))
269arr.push(reg46.test('héél'))
270
271let reg47 = /^[A-ZÄÖÜß]+$/i
272arr.push(reg47.test('äbc'))
273arr.push(reg47.test('FöÖbär'))
274
275let reg48 = /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i
276arr.push(reg48.test('árvíztűrőtükörfúrógép'))
277
278arr.forEach((item)=>{
279  if(!item){
280    temp = false
281  }
282})
283print(temp)
284
285let arr1 = []
286let temp1 = false
287let reg49 = /[^A-Z0-9+\/=]/i;
288arr1.push(reg49.test("Zg=="));
289arr1.push(reg49.test("Zm8="));
290arr1.push(reg49.test("Zm9v"));
291arr1.push(reg49.test("Zm9vYg=="));
292arr1.push(reg49.test("Zm9vYmE="));
293arr1.push(reg49.test("Zm9vYmFy"));
294arr1.push(reg49.test(
295  "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4="
296));
297arr1.push(reg49.test("Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg=="));
298arr1.push(reg49.test("U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw=="));
299arr1.forEach((item)=>{
300  if(item){
301    temp1 = true
302  }
303})
304print(temp1)
305let str1 = 'SC52BAHL01031234567890123456USD'
306print(str1.replace(/[^A-Z0-9]+/gi, ''))
307
308let reg50 = /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i
309
310let regabc = /abc/g;
311let strabcd = "abcdabcdabcd";
312for (let i = 0; i < 10; i++) {
313  // cache is used in this case
314  print(regabc.test(strabcd));
315}
316
317let str2 = "aaaabbBbcccC";
318for (let i = 0; i < 2; i++) {
319  print(str2);
320  let t1 = str2.replace(/([A-Z])/g, function(e) {
321    return "_" + e;
322  });
323  print(t1);
324  let t2 = str2.replace(/([A-Z])/g, "_$1");
325  print(t2);
326  print(t1.replace(/([a-z]+)/g, "_xy"));
327  print(t2.replace(/_/g, ""));
328}
329
330// regexp cache test
331let mediaReg = "\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)\([^\)]+\)";
332let 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';
333const regex1 = new RegExp(mediaReg);
334let matchArray = string.match(regex1);
335print(matchArray);
336
337// Test regexp.test fastpath
338var protoExec = RegExp.prototype.exec
339RegExp.prototype.exec = function () {
340  return null
341}
342var reg = /a/
343print(reg.test("aaaaa"));
344
345delete RegExp.prototype.exec
346print(reg.test("aaaaa"));
347
348Object.prototype.exec = function () {
349  return null
350}
351print(reg.test("aaaaa"));
352
353delete Object.prototype.exec
354RegExp.prototype.exec = protoExec
355print(reg.test("aaaaa"));
356
357var protoTest = RegExp.prototype.test
358RegExp.prototype.test = function () {
359    return false
360}
361var reg2 = /foo*/
362print(reg2.test("fooooooo"));
363
364RegExp.prototype.test = protoTest
365print(reg2.test("fooooooo"));
366
367// Same hash in cached result, but different flags.
368var regexp1 = /a*/gs;
369var regexp2 = /a*/g;
370regexp2.lastIndex = 8;
371print(regexp1.exec('aaa'));
372print(regexp2.exec('aaa'));
373
374// Same hash in cached result, and same flags, but different lastIndex.
375var regexp3 = /a*/g;
376var regexp4 = /a*/g;
377regexp4.lastIndex = 1;
378print(regexp3.exec('aaabab'));
379print(regexp4.exec('aaabaa'));
380
381const v43 = /V[\d-\d]/ys;
382const o54 = {
383    __proto__: v43,
384};
385try {
386    o54.test(Map);
387} catch (e) {
388    print(e)
389}
390
391// Testing regexp.prototype.replace after optimization
392{
393  const re1 = /[Cz]/;
394  const re2 = /[Cz]/g;
395  const re3 = /([Cz])/;
396  const re4 = /([Cz])/g;
397
398  let replace_str = "abCdefgzabCdefgzabCdefgz";
399  let replace_result = replace_str.replace(re1, "");
400  print(re1.lastIndex);
401  let cached_reuslt = replace_str.replace(re1, "");
402  print(replace_result === cached_reuslt);
403  print(re1.lastIndex);
404
405  replace_result = replace_str.replace(re2, "xyz");
406  print(re2.lastIndex);
407  cached_reuslt = replace_str.replace(re2, "xyz");
408  print(replace_result === cached_reuslt);
409  print(re2.lastIndex);
410
411  replace_result = replace_str.replace(re3, "x$1yz");
412  print(re3.lastIndex);
413  cached_reuslt = replace_str.replace(re3, "x$1yz");
414  print(replace_result === cached_reuslt);
415  print(re3.lastIndex);
416
417  replace_result = replace_str.replace(re4, String);
418  print(re4.lastIndex);
419  cached_reuslt = replace_str.replace(re4, String);
420  print(replace_result === cached_reuslt);
421  print(re4.lastIndex);
422}
423
424// test RegExp.prototype.xx
425print(RegExp.prototype.dotAll)
426print(RegExp.prototype.global)
427print(RegExp.prototype.hasIndices)
428print(RegExp.prototype.ignoreCase)
429print(RegExp.prototype.multiline)
430print(RegExp.prototype.sticky)
431print(RegExp.prototype.unicode)
432print(RegExp.prototype.lastIndex)
433print(RegExp.prototype.flags)
434print(RegExp.prototype.source)
435try {
436    RegExp.prototype.test("abc")
437} catch (e) {
438    print(e.name)
439}
440try {
441    RegExp.prototype.exec("abc")
442} catch (e) {
443    print(e.name)
444}
445print(RegExp.prototype.toString())
446
447
448let inputString = "/vedio/av{avid}{cid}";
449let extractedContent = inputString.match(/\{([^{}]+)\}/g);
450let replacedString = inputString.replace(/\{([^{}]+)\}/g, '(uuu)').replace(/\//g, "\\/");
451print(replacedString);
452
453let str = "beep boop   afff测试样本one1";
454print(str.split(/([{}:;,]|\s+)/));
455
456function verifyRegExp(text) {
457  text = text.replace(new RegExp('[\\s]', 'g'), ' ');
458  let emRegExp = new RegExp('<em>.*?</em>', 'ig');
459  let results = text.split(emRegExp);
460  text.match(emRegExp);
461  return results;
462}
463
464const srcTextA = '<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz<em>a</em>bcdefghijklmnopqrstuvwxyz'
465const srcTextAbcd = '<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz<em>abcd</em>efghijklmnopqrstuvwxyz'
466
467print(`verifyRegExp_1: ${verifyRegExp(srcTextA)}`);
468print(`verifyRegExp_2: ${verifyRegExp(srcTextAbcd)}`);
469print(`verifyRegExp_3: ${verifyRegExp(srcTextAbcd)}`);
470
471//regexp unicode property
472const ans1 = /\p{Alphabetic}/u.test("æ");
473const ans2 = /\p{Alpha}/u.test("2");
474const ans3 = /^[\p{Lu}\p{Ll}]+$/u.test("ASDFasdf");
475const ans4 = /^[\P{Lu}\p{Ll}]+$/u.test("ASDFasdf");
476const ans5 = /\P{Ll}/iu.test("b");
477const ans6 = /\p{Ll}/iu.test("b");
478const ans7 = /[^\P{Any}]+/u.test(456);
479const ans8 = /\p{Assigned}+/u.test("������");
480const ans9 = /[\p{P}\p{S}]/u.test("!");
481const ans10 = /\p{General_Category=Math_Symbol}/u.test("+");
482print(ans1);
483print(ans2);
484print(ans3);
485print(ans4);
486print(ans5);
487print(ans6);
488print(ans7);
489print(ans8);
490print(ans9);
491print(ans10);
492try {
493  const ans11 = RegExp("/[\\p{}]/u");
494  print(ans11);
495} catch(e) {
496  print(e);
497}
498
499try {
500  let matchReg = new RegExp("@【哈哈】*^o^*|@小米(kk)",'g');
501} catch (error) {
502  print(error)
503}
504const str3 = "a-b-c";
505const re = /-/y;
506print(str3.split(re));
507
508re.lastIndex = 1;
509print(str3.split(re));
510
511re.lastIndex = -1;
512print(str3.split(re));
513
514re.lastIndex = 3;
515print(str3.split(re));
516
517print(re.test(str3));
518
519print(str3.split(/-/g));
520
521// search
522const str4 = "abc";
523let re1 = /b/;
524re1.lastIndex = 2;
525print(str4.search(re1));
526print(str4.search(/b/y));
527print(str4.search(re1));
528print(re1.lastIndex);
529
530// check cache
531const str5 = "a-bc";
532let re2 = /-/;
533re2.lastIndex = 2;
534print(str5.split(re2));
535print(re2.lastIndex);
536print(str5.split(re2));
537print(re2.lastIndex);
538
539const str6 = "abcabc";
540let re3 = /abc/;
541re3.lastIndex = 2;
542print(str6.match(re3));
543print(re3.lastIndex);
544print(str6.match(re3));
545print(re3.lastIndex);
546
547let re4 = /abc/g;
548re4.lastIndex = 2;
549print(str6.match(re4));
550print(re4.lastIndex);
551print(str6.match(re4));
552print(re4.lastIndex);
553Object.defineProperty(RegExp.prototype, "global", {
554  value: true
555})
556var flags = RegExp.prototype.flags;
557Object.defineProperty(RegExp.prototype, "global", {
558  value: false
559})
560print(flags);
561print(str6.match(re4));
562print(re4.lastIndex);
563print(str6.match(re4));
564print(re4.lastIndex);
565
566let myExp = new RegExp("a+b+c");
567Object.defineProperty(myExp, "sticky", {
568    value: true
569  })
570print(myExp.toString());
571
572// Testing regexp.prototype.replace after optimization
573{
574  const re1 = /[Cz]/;
575  const re2 = /[Cz]/g;
576  const re3 = /([Cz])/;
577  const re4 = /([Cz])/g;
578
579  let replace_str = "abCdefgzabCdefgzabCdefgz";
580  let replace_result = replace_str.replace(re1, "");
581  print(re1.lastIndex);
582  let cached_reuslt = replace_str.replace(re1, "");
583  print(replace_result === cached_reuslt);
584  print(re1.lastIndex);
585
586  replace_result = replace_str.replace(re2, "xyz");
587  print(re2.lastIndex);
588  cached_reuslt = replace_str.replace(re2, "xyz");
589  print(replace_result === cached_reuslt);
590  print(re2.lastIndex);
591
592  replace_result = replace_str.replace(re3, "x$1yz");
593  print(re3.lastIndex);
594  cached_reuslt = replace_str.replace(re3, "x$1yz");
595  print(replace_result === cached_reuslt);
596  print(re3.lastIndex);
597
598  replace_result = replace_str.replace(re4, String);
599  print(re4.lastIndex);
600  cached_reuslt = replace_str.replace(re4, String);
601  print(replace_result === cached_reuslt);
602  print(re4.lastIndex);
603}
604
605const regex = /(?:)+/;
606const str10 = "abcabcabc";
607const matches = regex.test(str10);
608print(matches);
609const matches1 = regex.exec(str10);
610print(matches1);
611
612let e = /./;
613e.exec = function() {
614    return [];
615}
616"".replace(e, "");
617delete e.exec;
618
619{
620  const v0 = /qeu(?<a>.)\k<a>(x)(x)(x)\1*xyz{93}/ugysd;
621  const v4 = typeof Date === "string";
622  v0[Symbol.match] = v4;
623  print(v0["exec"]());
624}
625
626{
627  ("65535").split(/(?!\1(a\1)\1)\1/g);
628  const o4 = {
629    ...RegExp,
630  };
631  print(o4);
632}
633
634{
635  let str = /^\s*([^;\s]*)/;
636  str.test("text/html");
637  print(RegExp.$1);
638  str.test("text/plain");
639  print(RegExp.$1);
640  str.test("text/html");
641  print(RegExp.$1);
642  const v2 = /e\8Z(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\10*/misd;
643  v2[1073741824] = -194290175n;
644  for (let v3 = 0; v3 < 2; v3++) {
645    print(v2.test(-194290175n));
646  }
647}
648
649function f(...args) {
650  return {};
651}
652let reg51 = new RegExp("a");
653f.exec = f;
654let relpfun = reg51[Symbol.replace];
655relpfun.apply(f, [1, 2, 3, 4]);
656print("success");
657{
658  let reg52 = /abc/;
659  let count = 0;
660  print(reg52.ignoreCase);
661  print(reg52.global);
662  print(reg52.flags);
663  Object.defineProperty(reg52, "global", {
664    get: function() { count++; return true; }
665  });
666  Object.defineProperty(reg52, "ignoreCase", {
667    get: function() { count++; return true; }
668  });
669  print(reg52.ignoreCase);
670  print(count);
671  print(reg52.global);
672  print(count);
673  print(reg52.flags);
674  print(count);
675}
676
677// The above test case in false environment did not reset the environment
678Object.defineProperty(RegExp.prototype, "global", {
679  value: true
680})
681string = 'aaa\n789\r\nccc\r\n345';
682var pattern = /\d$/gm;
683result = string.match(pattern);
684print(2 == result.length);
685print('9' == result[0]);
686print('5' == result[1]);
687
688string = 'aaa\n789\r\nccc\r\nddd';
689pattern = /\d$/gm;
690result = string.match(pattern);
691print(1 == result.length);
692print('9' == result[0]);