• 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 */
22var reg = /[\x5d-\x7e]/i;
23var result = reg.test("a");
24print(result);
25
26var reg1 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$");
27var result1 = reg1.test('0٫0000000000001');
28print(result1);
29
30var reg2 = /^[Α-ώ]+$/i
31print(reg2.test('άέήίΰϊϋόύώ'));
32
33print(reg2.test('ΆΈΉΊΪΫΎΏ'));
34
35print(reg2.test('αβγδεζηθικλμνξοπρςστυφχψω'));
36
37print(reg2.test('ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'));
38
39let reg3 =/^[A-Z0-9_\-]*$/i
40print(reg3.test(''))
41
42let reg4 =   new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>https?[::]//[^/]+/svn(?:/[a-z0-9.,;?'*:+&%$#=~_ \\u4E00-\\u9FA5-]*)*).*$", "i")
43print(reg4.test('a'));
44
45let 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")
46print(reg5.test('a'));
47
48let reg6 =   new RegExp("^(?<urlStrIndex>.*?)(?<urlStr>(?:ht|f)tps?[::]//(?:[a-z0-9-]+\\.)*[a-z0-9-]+(?:/[a-z0-9]+)*[/a-z0-9.,;?'\\|*:\\\\+&%$#=~_-]*).*$", "i")
49print(reg6.test('a'));
50
51let 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")
52print(reg7.test('a'));
53
54let arr = []
55let temp = true
56var 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;
57arr.push(quotedEmailUserUtf8.test(" foo m端ller "))
58
59let reg8 = /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i
60arr.push(reg8.test('palíndromo'))
61arr.push(reg8.test('órgão'))
62arr.push(reg8.test('qwértyúão'))
63arr.push(reg8.test('àäãcëüïÄÏÜ'))
64
65let reg9 = /^[A-ZÀÉÈÌÎÓÒÙ]+$/i
66arr.push(reg9.test('àéèìîóòù'))
67arr.push(reg9.test('metró'))
68arr.push(reg9.test('pèsca'))
69arr.push(reg9.test('genî'))
70
71let reg10 = /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i
72arr.push(reg10.test('thiến'))
73arr.push(reg10.test('nghiêng'))
74arr.push(reg10.test('chào'))
75arr.push(reg10.test('thế'))
76arr.push(reg10.test('giới'))
77
78let reg11 = /^[A-ZÅÄÖ]+$/i
79arr.push(reg11.test('äiti'))
80
81let reg12 = /^[A-ZÆØÅ]+$/i
82arr.push(reg12.test('aøå'))
83
84let reg13 = /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i
85arr.push(reg13.test('kreską'))
86arr.push(reg13.test('zamknięte'))
87arr.push(reg13.test('zwykłe'))
88arr.push(reg13.test('kropką'))
89arr.push(reg13.test('przyjęły'))
90arr.push(reg13.test('święty'))
91arr.push(reg13.test('Pozwól'))
92
93let reg14 = /^[А-ЯЂЈЉЊЋЏ]+$/i
94arr.push(reg14.test('ШћжЂљЕ'))
95
96let reg15 = /^[A-ZČĆŽŠĐ]+$/i
97arr.push(reg15.test('ŠAabčšđćž'))
98arr.push(reg15.test('ŠATROĆčđš'))
99
100let reg16 = /^[A-ZÁÉÍÑÓÚÜ]+$/i
101arr.push(reg16.test('ábcó'))
102arr.push(reg16.test('dormís'))
103arr.push(reg16.test('volvés'))
104arr.push(reg16.test('español'))
105
106let reg17 = /^[A-ZÅÄÖ]+$/i
107arr.push(reg17.test('religiös'))
108arr.push(reg17.test('stjäla'))
109arr.push(reg17.test('västgöte'))
110
111let reg18 = /^[A-ZÇĞİıÖŞÜ]+$/i
112arr.push(reg18.test('AİıÖöÇ窺ĞğÜüZ'))
113
114let reg19 = /^[Α-ώ]+$/i
115arr.push(reg19.test('άέήίΰϊϋόύώ'))
116arr.push(reg19.test('ΆΈΉΊΪΫΎΏ'))
117
118let reg20 = /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i
119arr.push(reg20.test('Azərbaycan'))
120arr.push(reg20.test('abcç2'))
121arr.push(reg20.test('3kərə4kərə'))
122
123let reg21 = /^[0-9А-Я]+$/i
124arr.push(reg21.test('абв1'))
125arr.push(reg21.test('жаба'))
126arr.push(reg21.test('яГоДа2'))
127arr.push(reg21.test('йЮя'))
128
129let reg22 = /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i
130arr.push(reg22.test('řiť123'))
131
132let reg23 = /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i
133arr.push(reg23.test('1môj'))
134arr.push(reg23.test('2ľúbím'))
135arr.push(reg23.test('3mäkčeň'))
136arr.push(reg23.test('5vŕba'))
137arr.push(reg23.test('6ňorimberk'))
138arr.push(reg23.test('7ťava'))
139arr.push(reg23.test('8žanéta'))
140arr.push(reg23.test('9Ďábelské'))
141arr.push(reg23.test('10ódy'))
142
143let reg24 = /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i
144arr.push(reg24.test('Kán123'))
145arr.push(reg24.test('één354'))
146
147let reg25 = /^[0-9A-ZÅÄÖ]+$/i
148arr.push(reg25.test('äiti124'))
149arr.push(reg25.test('451åå23'))
150
151let reg26 = /^[0-9A-ZÄÖÜß]+$/i
152arr.push(reg26.test('äbc123'))
153
154let reg27 = /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i
155arr.push(reg27.test('0árvíztűrőtükörfúrógép123'))
156
157let reg28 = /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i
158arr.push(reg28.test('palíndromo'))
159arr.push(reg28.test('2órgão'))
160arr.push(reg28.test('qwértyúão9'))
161arr.push(reg28.test('àäãcë4üïÄÏÜ'))
162
163let reg29 = /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i
164arr.push(reg29.test('123àéèìîóòù'))
165arr.push(reg29.test('met23ró'))
166arr.push(reg29.test('pès56ca'))
167arr.push(reg29.test('gen45î'))
168
169let reg30 = /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i
170arr.push(reg30.test('ábcó123'))
171
172let reg31 = /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i
173arr.push(reg31.test('Thầy3'))
174arr.push(reg31.test('3Gà'))
175
176let reg32 = /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i
177arr.push(reg32.test('kre123ską'))
178arr.push(reg32.test('zam21knięte'))
179arr.push(reg32.test('zw23ykłe'))
180arr.push(reg32.test('prz23yjęły'))
181arr.push(reg32.test('świ23ęty'))
182arr.push(reg32.test('Poz1322wól'))
183
184let reg33 = /^[0-9А-ЯЂЈЉЊЋЏ]+$/i
185arr.push(reg33.test('ШћжЂљЕ123'))
186
187let reg34 = /^[0-9A-ZČĆŽŠĐ]+$/i
188arr.push(reg34.test('ŠAabčšđćž123'))
189arr.push(reg34.test('ŠATRO11Ćčđš'))
190
191let reg35 = /^[0-9A-ZÅÄÖ]+$/i
192arr.push(reg35.test('religiös13'))
193arr.push(reg35.test('st23jäla'))
194arr.push(reg35.test('västgöte123'))
195
196let reg36 = /^[0-9A-ZÇĞİıÖŞÜ]+$/i
197arr.push(reg36.test('AİıÖöÇ窺ĞğÜüZ123'))
198
199let reg37 = new RegExp("^[-+]?([0-9]+)?(\\٫[0-9]{1,})?$")
200arr.push(reg37.test('0٫0000000000001'))
201
202let reg38 = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\٫[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")
203arr.push(reg38.test('123٫'))
204arr.push(reg38.test('123٫123'))
205arr.push(reg38.test('-123٫123'))
206
207let reg39 =/^[A-Z0-9_\-]*$/i
208arr.push(reg39.test(''))
209
210let reg40 = RegExp("^(?!-? )(?=.*\\d)(\\¥)?-?(0|[1-9]\\d|[1-9]\\d{0,2}(\\,\\d{3})*)?(\\.(\\d{2}))?$")
211arr.push(reg40.test('¥6,954,231'))
212arr.push(reg40.test('¥-6,954,231'))
213
214var reg41 = /^[A-VXYZÇƏĞİıÖŞÜ]+$/i;
215arr.push(reg41.test('Azərbaycan'))
216arr.push(reg41.test('üöğıəçş'))
217arr.push(reg41.test('sizAzərbaycanlaşdırılmışlardansınızmı'))
218arr.push(reg41.test('dahaBirDüzgünString'))
219arr.push(reg41.test('abcçdeəfgğhxıijkqlmnoöprsştuüvyz'))
220
221let reg42 = /^[А-Я]+$/i
222arr.push(reg42.test('абв'))
223arr.push(reg42.test('жаба'))
224arr.push(reg42.test('яГоДа'))
225
226let reg43 = /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i
227arr.push(reg43.test('žluťoučký'))
228arr.push(reg43.test('Pěl'))
229arr.push(reg43.test('Ďábelské'))
230arr.push(reg43.test('ódy'))
231
232let reg44 = /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i
233arr.push(reg44.test('môj'))
234arr.push(reg44.test('ľúbím'))
235arr.push(reg44.test('mäkčeň'))
236arr.push(reg44.test('vŕba'))
237arr.push(reg44.test('ňorimberk'))
238
239let reg45 = /^[A-ZÆØÅ]+$/i
240arr.push(reg45.test('aøå'))
241
242let reg46 = /^[A-ZÁÉËÏÓÖÜÚ]+$/i
243arr.push(reg46.test('Kán'))
244arr.push(reg46.test('één'))
245arr.push(reg46.test('vóór'))
246arr.push(reg46.test('nú'))
247arr.push(reg46.test('héél'))
248
249let reg47 = /^[A-ZÄÖÜß]+$/i
250arr.push(reg47.test('äbc'))
251arr.push(reg47.test('FöÖbär'))
252
253let reg48 = /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i
254arr.push(reg48.test('árvíztűrőtükörfúrógép'))
255
256arr.forEach((item)=>{
257  if(!item){
258    temp = false
259  }
260})
261print(temp)
262
263let arr1 = []
264let temp1 = false
265let reg49 = /[^A-Z0-9+\/=]/i;
266arr1.push(reg49.test("Zg=="));
267arr1.push(reg49.test("Zm8="));
268arr1.push(reg49.test("Zm9v"));
269arr1.push(reg49.test("Zm9vYg=="));
270arr1.push(reg49.test("Zm9vYmE="));
271arr1.push(reg49.test("Zm9vYmFy"));
272arr1.push(reg49.test(
273  "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4="
274));
275arr1.push(reg49.test("Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg=="));
276arr1.push(reg49.test("U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw=="));
277arr1.forEach((item)=>{
278  if(item){
279    temp1 = true
280  }
281})
282print(temp1)
283let str1 = 'SC52BAHL01031234567890123456USD'
284print(str1.replace(/[^A-Z0-9]+/gi, ''))
285
286let reg50 = /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i
287
288const regex = /(?:)+/;
289const str10 = "abcabcabc";
290const matches = regex.test(str10);
291print(matches);
292const matches1 = regex.exec(str10);
293print(matches1);