mm_matchs 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/htmlformat.js DELETED
@@ -1,396 +0,0 @@
1
- function styleHtml(html_source, indent_size, indent_char, max_char) {
2
- //Wrapper function to invoke all the necessary constructors and deal with the output.
3
-
4
- var parser, multi_parser;
5
-
6
- function parser() {
7
-
8
- this.pos = 0; //Parser position
9
- this.token = '';
10
- this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
11
- this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
12
- parent: 'parent1',
13
- parentcount: 1,
14
- parent1: ''
15
- };
16
- this.tag_type = '';
17
- this.token_text = this.last_token = this.last_text = this.token_type = '';
18
-
19
-
20
- this.Utils = { //Uilities made available to the various functions
21
- whitespace: '\n\r\t '.split(''),
22
- single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed'.split(','), //all the single tags for HTML
23
- extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
24
- inArray: function (what, arr) {
25
- var len = arr.length;
26
- for (var i = 0; i < len; i++) {
27
- if (what === arr[i]) {
28
- return true;
29
- }
30
- }
31
- return false;
32
- }
33
- };
34
-
35
- this.getContent = function () { //function to capture regular content between tags
36
-
37
- var char = '';
38
- var content = [];
39
- var space = false; //if a space is needed
40
- while (this.input.charAt(this.pos) !== '<') {
41
- if (this.pos >= this.input.length) {
42
- return content.length ? content.join('') : ['', 'TK_EOF'];
43
- }
44
-
45
- char = this.input.charAt(this.pos);
46
- this.pos++;
47
- this.line_char_count++;
48
-
49
-
50
- if (this.Utils.in_array(char, this.Utils.whitespace)) {
51
- if (content.length) {
52
- space = true;
53
- }
54
- this.line_char_count--;
55
- continue; //don't want to insert unnecessary space
56
- } else if (space) {
57
- if (this.line_char_count >= this.max_char) { //insert a line when the max_char is reached
58
- content.push('\n');
59
- for (var i = 0; i < this.indent_level; i++) {
60
- content.push(this.indent_string);
61
- }
62
- this.line_char_count = 0;
63
- } else {
64
- content.push(' ');
65
- this.line_char_count++;
66
- }
67
- space = false;
68
- }
69
- content.push(char); //letter at-a-time (or string) inserted to an array
70
- }
71
- return content.length ? content.join('') : '';
72
- };
73
-
74
- this.getScript = function () { //get the full content of a script to pass to js_beautify
75
-
76
- var char = '';
77
- var content = [];
78
- var reg_match = this.regex.scriptEndTag;
79
- reg_match.lastIndex = this.pos;
80
- var reg = reg_match.exec(this.input);
81
- var end_script = reg_array ? reg_array.index : this.input.length; //absolute end of script
82
- while (this.pos < end_script) { //get everything in between the script tags
83
- if (this.pos >= this.input.length) {
84
- return content.length ? content.join('') : ['', 'TK_EOF'];
85
- }
86
-
87
- char = this.input.charAt(this.pos);
88
- this.pos++;
89
-
90
-
91
- content.push(char);
92
- }
93
- return content.length ? content.join('') : ''; //we might not have any content at all
94
- };
95
-
96
- this.recordTag = function (tag) { //function to record a tag and its parent in this.tags Object
97
- if (this.tags[tag + 'count']) { //check for the existence of this tag type
98
- this.tags[tag + 'count']++;
99
- this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
100
- } else { //otherwise initialize this tag type
101
- this.tags[tag + 'count'] = 1;
102
- this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
103
- }
104
- this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
105
- this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
106
- };
107
-
108
- this.retrieveTag = function (tag) { //function to retrieve the opening tag to the corresponding closer
109
- if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
110
- var parent = this.tags.parent; //check to see if it's a closable tag.
111
- while (temp_parent) { //till we reach '' (the initial value);
112
- if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
113
- break;
114
- }
115
- temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
116
- }
117
- if (temp_parent) { //if we caught something
118
- this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
119
- this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
120
- }
121
- delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
122
- delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
123
- if (this.tags[tag + 'count'] == 1) {
124
- delete this.tags[tag + 'count'];
125
- } else {
126
- this.tags[tag + 'count']--;
127
- }
128
- }
129
- };
130
-
131
- this.getTag = function () { //function to get a full tag and parse its type
132
- var char = '';
133
- var content = [];
134
- var space = false;
135
-
136
- do {
137
- if (this.pos >= this.input.length) {
138
- return content.length ? content.join('') : ['', 'TK_EOF'];
139
- }
140
-
141
- char = this.input.charAt(this.pos);
142
- this.pos++;
143
- this.line_char_count++;
144
-
145
- if (this.Utils.in_array(char, this.Utils.whitespace)) { //don't want to insert unnecessary space
146
- space = true;
147
- this.line_char_count--;
148
- continue;
149
- }
150
-
151
- if (char === "'" || char === '"') {
152
- if (!content[1] || content[1] !== '!') { //if we're in a comment strings don't get treated specially
153
- char += this.getUnfo(char);
154
- space = true;
155
- }
156
- }
157
-
158
- if (char === '=') { //no space before =
159
- space = false;
160
- }
161
-
162
- if (content.length && content[content.length - 1] !== '=' && char !== '>' &&
163
- space) { //no space after = or before >
164
- if (this.line_char_count >= this.max_char) {
165
- this.printNewline(false, content);
166
- this.line_char_count = 0;
167
- } else {
168
- content.push(' ');
169
- this.line_char_count++;
170
- }
171
- space = false;
172
- }
173
- content.push(char); //inserts character at-a-time (or string)
174
- } while (char !== '>');
175
-
176
- var tag_complete = content.join('');
177
- var tag;
178
- if (tag_complete.indexOf(' ') != -1) { //if there's whitespace, thats where the tag name ends
179
- tag_index = tag_complete.indexOf(' ');
180
- } else { //otherwise go with the tag ending
181
- tag_index = tag_complete.indexOf('>');
182
- }
183
- var tag_check = tag_complete.substring(1, tag_index).toLowerCase();
184
- if (tag_complete.charAt(tag_complete.length - 2) === '/' ||
185
- this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
186
- this.tag_type = 'SINGLE';
187
- } else if (tag_check === 'script') { //for later script handling
188
- this.recordTag(tag_check);
189
- this.tag_type = 'SCRIPT';
190
- } else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
191
- this.recordTag(tag_check);
192
- this.tag_type = 'STYLE';
193
- } else if (tag_check.charAt(0) === '!') { //peek for <!-- comment
194
- if (tag_check.indexOf('[if') != -1) { //peek for <!--[if conditional comment
195
- if (tag_complete.indexOf('!IE') != -1) { //this type needs a closing --> so...
196
- var comment = this.getUnfo(this.regex.commentEnd, tag_complete); //...delegate to get_unformatted
197
- content.push(comment);
198
- }
199
- this.tag_type = 'START';
200
- } else if (tag_check.indexOf('[endif') != -1) { //peek for <!--[endif end conditional comment
201
- this.tag_type = 'END';
202
- this.unindent();
203
- } else if (tag_check.indexOf('[cdata[') != -1) { //if it's a <[cdata[ comment...
204
- var comment = this.getUnfo(this.regex.cdataEnd, tag_complete); //...delegate to get_unformatted function
205
- content.push(comment);
206
- this.tag_type = 'SINGLE'; //<![CDATA[ comments are treated like single tags
207
- } else {
208
- var comment = this.getUnfo('-->', tag_complete);
209
- content.push(comment);
210
- this.tag_type = 'SINGLE';
211
- }
212
- } else {
213
- if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
214
- this.retrieveTag(tag_check.substring(1)); //remove it and all ancestors
215
- this.tag_type = 'END';
216
- } else { //otherwise it's a start-tag
217
- this.recordTag(tag_check); //push it on the tag stack
218
- this.tag_type = 'START';
219
- }
220
- if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
221
- this.printNewline(true, this.output);
222
- }
223
- }
224
- return content.join(''); //returns fully formatted tag
225
- };
226
-
227
- this.getUnfo = function (delimiter, orig_tag) { //function to return unformatted content in its entirety
228
-
229
- if (orig_tag && orig_tag.indexOf(delimiter) != -1) {
230
- return '';
231
- }
232
- var char = '';
233
- var content = '';
234
- var space = true;
235
- do {
236
-
237
- char = this.input.charAt(this.pos);
238
- this.pos++;
239
-
240
- if (this.Utils.in_array(char, this.Utils.whitespace)) {
241
- if (!space) {
242
- this.line_char_count--;
243
- continue;
244
- }
245
- if (char === '\n' || char === '\r') {
246
- content += '\n';
247
- for (var i = 0; i < this.indent_level; i++) {
248
- content += this.indent_string;
249
- }
250
- space = false; //...and make sure other indentation is erased
251
- this.line_char_count = 0;
252
- continue;
253
- }
254
- }
255
- content += char;
256
- this.line_char_count++;
257
- space = true;
258
-
259
-
260
- } while (content.indexOf(delimiter) == -1);
261
- return content;
262
- };
263
-
264
- this.getToken = function () { //initial handler for token-retrieval
265
- var token;
266
-
267
- if (this.last_token === 'TK_TAG_SCRIPT') { //check if we need to format javascript
268
- var token = this.getScript();
269
- if (typeof temp_token !== 'string') {
270
- return temp_token;
271
- }
272
- token = js_beautify(temp_token, this.indent_size, this.indent_character, this.indent_level); //call the JS Beautifier
273
- return [token, 'TK_CONTENT'];
274
- }
275
- if (this.current_mode === 'CONTENT') {
276
- token = this.getContent();
277
- if (typeof token !== 'string') {
278
- return token;
279
- } else {
280
- return [token, 'TK_CONTENT'];
281
- }
282
- }
283
-
284
- if (this.current_mode === 'TAG') {
285
- token = this.getTag();
286
- if (typeof token !== 'string') {
287
- return token;
288
- } else {
289
- var tag_name_type = 'TK_TAG_' + this.tag_type;
290
- return [token, tag_name_type];
291
- }
292
- }
293
- };
294
-
295
- this.printer = function (js_source, indent_char, indent_size, max_char) { //handles input/output and some other printing functions
296
-
297
- this.input = js_source || ''; //gets the input for the Parser
298
- this.output = [];
299
- this.indent_character = indent_character || ' ';
300
- this.indent_string = '';
301
- this.indent_size = indent_size || 2;
302
- this.indent_level = 0;
303
- this.max_char = max_char || 7000; //maximum amount of characters per line
304
- this.line_char_count = 0; //count to see if max_char was exceeded
305
-
306
- for (var i = 0; i < this.indent_size; i++) {
307
- this.indent_string += this.indent_character;
308
- }
309
-
310
- this.printNewline = function (ignore, arr) {
311
- this.line_char_count = 0;
312
- if (!arr || !arr.length) {
313
- return;
314
- }
315
- if (!ignore) { //we might want the extra line
316
- while (this.Utils.in_array(arr[arr.length - 1], this.Utils.whitespace)) {
317
- arr.pop();
318
- }
319
- }
320
- arr.push('\n');
321
- for (var i = 0; i < this.indent_level; i++) {
322
- arr.push(this.indent_string);
323
- }
324
- };
325
-
326
-
327
- this.printToken = function (text) {
328
- this.output.push(text);
329
- };
330
-
331
- this.indent = function () {
332
- this.indent_level++;
333
- };
334
-
335
- this.unindent = function () {
336
- if (this.indent_level > 0) {
337
- this.indent_level--;
338
- }
339
- };
340
- };
341
- return this;
342
- }
343
-
344
- /*_____________________--------------------_____________________*/
345
-
346
-
347
- multi_parser = new Parser(); //wrapping functions Parser
348
- multi_parser.printer(html_source, indent_character, indent_size); //initialize starting values
349
-
350
- var f = true;
351
- while (true) {
352
- var t = multi_parser.get_token();
353
- multi_parser.token_text = t[0];
354
- multi_parser.token_type = t[1];
355
-
356
- if (multi_parser.token_type === 'TK_EOF') {
357
- break;
358
- }
359
-
360
- switch (multi_parser.token_type) {
361
- case 'TK_TAG_START':
362
- case 'TK_TAG_SCRIPT':
363
- case 'TK_TAG_STYLE':
364
- multi_parser.print_newline(false, multi_parser.output);
365
- multi_parser.print_token(multi_parser.token_text);
366
- multi_parser.indent();
367
- multi_parser.current_mode = 'CONTENT';
368
- break;
369
- case 'TK_TAG_END':
370
- if (f)
371
- multi_parser.print_newline(true, multi_parser.output);
372
- multi_parser.print_token(multi_parser.token_text);
373
- multi_parser.current_mode = 'CONTENT';
374
- f = true;
375
- break;
376
- case 'TK_TAG_SINGLE':
377
- multi_parser.print_newline(false, multi_parser.output);
378
- multi_parser.print_token(multi_parser.token_text);
379
- multi_parser.current_mode = 'CONTENT';
380
- break;
381
- case 'TK_CONTENT':
382
- if (multi_parser.token_text !== '') {
383
- f = false;
384
- //multi_parser.print_newline(false, multi_parser.output);
385
- multi_parser.print_token(multi_parser.token_text);
386
- }
387
- multi_parser.current_mode = 'TAG';
388
- break;
389
- }
390
- multi_parser.last_token = multi_parser.token_type;
391
- multi_parser.last_text = multi_parser.token_text;
392
- }
393
- return multi_parser.output.join('');
394
- }
395
-
396
- module.exports = style_html;
package/lang.js DELETED
@@ -1,5 +0,0 @@
1
- // 名词、形容词、代词、数词、冠词、动词、副词、介词、连词、感叹词
2
-
3
- // 待添加的匹配有:颜色、水果、蔬菜、动物、植物、厨具、家具、电器、海鲜
4
- // 待完善的有格式顺序问题,例如:在*{方位}
5
-
@@ -1,16 +0,0 @@
1
- 'use strict';
2
- const fs = require('fs');
3
- const path = require('path');
4
- /** 模块能力层:懒加载工具实现,避免模块入口被 require 时加载全部实现 */
5
- module.exports = new Proxy({}, {
6
- get(_t, key) {
7
- if (typeof key !== 'string') return undefined;
8
- if (!fs.existsSync(path.join(__dirname, key, 'index.js'))) return undefined;
9
- return require('./' + key);
10
- },
11
- has(_t, key) {
12
- return typeof key === 'string' && fs.existsSync(path.join(__dirname, key, 'index.js'));
13
- },
14
- ownKeys() { return fs.readdirSync(__dirname, { withFileTypes: true }).filter(e => e.isDirectory()).map(e => e.name); },
15
- getOwnPropertyDescriptor(_t, key) { return this.has(_t, key) ? { enumerable: true, configurable: true } : undefined; }
16
- });
@@ -1,47 +0,0 @@
1
- /**
2
- * 文本模式匹配器
3
- * 基于 Matchs 把中文占位符格式转为正则,并从文本中提取匹配内容
4
- * @param {object} params 步骤参数
5
- * @param {object} ctx 上下文对象
6
- * @returns {object} 匹配结果
7
- */
8
- const { matchsAdmin } = require('../../../index.js');
9
-
10
- async function main(params, ctx, options) {
11
- void options;
12
- var action = params.action || 'get';
13
- var matchs = matchsAdmin(params.scope || 'os');
14
-
15
- try {
16
- if (!params.format) {
17
- throw new TypeError('缺少 format 匹配格式参数');
18
- }
19
-
20
- switch (action) {
21
- case 'get': {
22
- if (typeof params.text !== 'string') {
23
- throw new TypeError('get 需要 text 字符串参数');
24
- }
25
- ctx.output = { text: matchs.get(params.text, params.format) };
26
- break;
27
- }
28
-
29
- case 'to_regex':
30
- ctx.output = { regex: String(matchs.toRegex(params.format)) };
31
- break;
32
-
33
- default:
34
- ctx.output = {
35
- error: { code: 'MTC_UNKNOWN_ACTION', message: '不支持的操作: ' + action }
36
- };
37
- }
38
- } catch (e) {
39
- ctx.output = {
40
- error: { code: 'MATCH_ERROR', message: e.message }
41
- };
42
- }
43
-
44
- return ctx.output;
45
- }
46
-
47
- module.exports = { main };
package/test.js DELETED
@@ -1,216 +0,0 @@
1
- const Matchs = require('./index.js');
2
-
3
- // 测试中仅使用 $ 的日志输出能力,这里用 console 作为日志对象
4
- const $ = { log: console };
5
-
6
- async function test() {
7
- const ms = new Matchs();
8
- let str = '';
9
- // 基础匹配测试 OK
10
- $.log.debug('=== 基础匹配测试 ===');
11
- str = '职位不对的';
12
- $.log.debug(str.matchs('*{不对}'));
13
-
14
- // 数字正则匹配测试 OK
15
- $.log.debug('\n=== 数字匹配测试 ===');
16
- $.log.debug('今年28岁了'.matchs('/[0-9]+/'));
17
- $.log.debug('手机号码是15817188866,哦5646546'.matchs('/[0-9]+/g'));
18
-
19
- // 通配符匹配测试 OK
20
- $.log.debug('\n=== 通配符匹配测试 ===');
21
- str = '我叫文武, 手机号码是1581718881';
22
- $.log.debug(str.matchs('手机号码*'));
23
- $.log.debug(str.matchs('*武'));
24
-
25
- str = '因为如果它是一只鸟,那么它就会飞';
26
- $.log.debug(str.matchs('它*'));
27
- $.log.debug(str.matchs('如果*鸟'));
28
- $.log.debug(str.matchs('如果*就*'));
29
- $.log.debug(str.matchs('*它*就*'));
30
-
31
- // 职位匹配测试 OK
32
- $.log.debug('\n=== 职位匹配测试 ===');
33
- const JOB_TESTS = [
34
- '酒店厨师长',
35
- '宠物美容师',
36
- '广告设计师',
37
- '游戏设计总监',
38
- '软件开发工程师'
39
- ];
40
- JOB_TESTS.forEach(job => $.log.debug(job.matchs('{职位}')));
41
- $.log.debug('游戏设计师'.matchs('{中文}'));
42
- $.log.debug('游戏设计师'.matchs('{职位}'));
43
- $.log.debug('游戏设计师'.matchs('{中文}{职位}'));
44
- $.log.debug('游戏设计师'.matchs('[\u4e00-\u9fa5]{2,4}{职位}'));
45
- $.log.debug('广告设计实习生'.matchs('[\u4e00-\u9fa5]{2,4}{职位}'));
46
- $.log.debug('广告设计学徒'.matchs('{中文}{2,4}{职位}'));
47
-
48
- // 日期时间测试
49
- $.log.debug('\n=== 日期时间测试 ===');
50
- str = '今天不是我的生日, 我是一九九一年四月一日生的,生日是4月1日';
51
- $.log.debug(str.matchs('{时态}'));
52
- $.log.debug(str.matchs('{日期}'));
53
- $.log.debug(str.matchs('{年月日}'));
54
- $.log.debug(str.matchs('{月日}'));
55
-
56
- str = '1991-04-01 12:15:36';
57
- $.log.debug(str.matchs('{年月日}'));
58
- $.log.debug(str.matchs('{月日}'));
59
- $.log.debug(str.matchs('{日期时间}'));
60
- $.log.debug(str.matchs('{时分}'));
61
- $.log.debug(str.matchs('{时分秒}'));
62
-
63
- str = '1991年4月1日,小宝宝诞生了';
64
- $.log.debug(str.matchs('{年月日}'));
65
- $.log.debug(str.matchs('{月日}'));
66
-
67
- str = '1991年04月01日 12时15分36秒';
68
- $.log.debug(str.matchs('{年月日}'));
69
- $.log.debug(str.matchs('{月日}'));
70
- $.log.debug(str.matchs('{日期时间}'));
71
- $.log.debug(str.matchs('{日期}'));
72
- $.log.debug(str.matchs('{时间}'));
73
- $.log.debug(str.matchs('{日期} {时间}'));
74
- $.log.debug(str.matchs('{时分}'));
75
- $.log.debug(str.matchs('{时分秒}'));
76
-
77
- // 周期匹配测试OK
78
- $.log.debug('\n=== 周期匹配测试 ===');
79
- const CYCLE_TESTS = [
80
- '十五天内',
81
- '10-15天左右',
82
- '十到十五天内',
83
- '10至15天内',
84
- '15号之前',
85
- '数日内',
86
- '几个小时后',
87
- '从现在起几个小时之内'
88
- ];
89
- CYCLE_TESTS.forEach(cycle => $.log.debug(cycle.matchs('{周期}')));
90
-
91
- // 手机号码和数字测试 OK
92
- $.log.debug('\n=== 手机号码和数字测试 ===');
93
- str = '我叫文武, 手机号码是15817188866';
94
- $.log.debug(str.matchs('{手机号码}'));
95
- $.log.debug(str.matchs('{数字}'));
96
-
97
- // 时间格式测试 OK
98
- $.log.debug('\n=== 时间格式测试 ===');
99
- const TIME_TESTS = [
100
- '现在的时间是十九点三十五分五十九秒',
101
- '现在的时间是19点35分59秒',
102
- '现在的时间是19:35:59'
103
- ];
104
- TIME_TESTS.forEach(time => {
105
- $.log.debug(time.matchs('{时间}'));
106
- $.log.debug(time.matchs('{时分秒}'));
107
- $.log.debug(time.matchs('{时分}'));
108
- });
109
-
110
- // 其他格式测试 OK
111
- $.log.debug('\n=== 其他格式测试 ===');
112
- const OTHER_TESTS = [{
113
- str: '星期天去哪玩?',
114
- pattern: '{星期}'
115
- },
116
- {
117
- str: 'http://www.elins.cn',
118
- pattern: '{网址}'
119
- },
120
- {
121
- str: '573242395@qq.com',
122
- pattern: '{邮箱}'
123
- },
124
- {
125
- str: '身份证号441423199104018012',
126
- pattern: '{身份证号}'
127
- },
128
- {
129
- str: 'QQ号是573242395',
130
- pattern: '{QQ}'
131
- },
132
- {
133
- str: 'my name is qww, QQ号是573242395',
134
- pattern: '{中英文}'
135
- },
136
- {
137
- str: '我的名字叫文武qww',
138
- pattern: '{中文或英文}'
139
- },
140
- {
141
- str: 'Hello World!',
142
- pattern: '{中英文}'
143
- },
144
- ];
145
- OTHER_TESTS.forEach(test => $.log.debug(test.str.matchs(test.pattern)));
146
-
147
- // HTML标签测试 OK
148
- $.log.debug('\n=== HTML标签测试 ===');
149
- str = '<img src="http://www.elins.cn/logo.png" />';
150
- $.log.debug(str.matchs('{img标签}'));
151
- $.log.debug(str.matchs('{网址}'));
152
- $.log.debug(str.matchs('{域名}'));
153
- str = `这是一个链接<a href="http://www.elins.cn/logo.png">
154
- <div class="test">你好吗?</div>
155
- </a>`;
156
- $.log.debug(str.matchs('{链接}'));
157
- $.log.debug(str.matchs('{html标签}'));
158
- $.log.debug(str.matchs('{标签之间}'));
159
-
160
- // 地理位置测试OK
161
- $.log.debug('\n=== 地理位置测试 ===');
162
- str = '广东省深圳市南山区粤海街道在中国南方';
163
- $.log.debug(str.matchs('{省份}'));
164
- $.log.debug(str.matchs('{城市}'));
165
- $.log.debug(str.matchs('{管辖区}'));
166
- $.log.debug(str.matchs('{方位}'));
167
- $.log.debug(str.matchs('在*{方位}'));
168
- $.log.debug(str.matchs('在{国家}'));
169
-
170
- // 车牌和数字测试OK
171
- $.log.debug('\n=== 车牌和数字测试 ===');
172
- $.log.debug('我乘坐的车的车牌号是粤B12312'.matchs('{车牌号}'));
173
- $.log.debug('圆周率是3.1415926'.matchs('{浮点数}'));
174
- $.log.debug('圆周率是3.1415926'.matchs('{数值}'));
175
- $.log.debug('圆周率是3.1415926'.matchs('{数字}'));
176
-
177
- // 疑问句测试OK
178
- $.log.debug('\n=== 疑问句测试 ===');
179
- const QUESTION_TESTS = [
180
- '做到了什么程度?',
181
- '买了什么东西?',
182
- '摸到了什么东西?',
183
- '获得了什么东西?',
184
- '想到了什么?',
185
- '今天天气怎么样?',
186
- '听见什么没?',
187
- '你到哪里了?',
188
- '买到了没?'
189
- ];
190
- QUESTION_TESTS.forEach(q => $.log.debug(q.matchs('{疑问}')));
191
-
192
- // 颜色测试OK
193
- $.log.debug('\n=== 颜色测试 ===');
194
- const COLOR_TESTS = ['紫红色', '朱红色', '大红大紫', '深红色', '浅绿色', '墨黑色'];
195
- COLOR_TESTS.forEach(color => $.log.debug(color.matchs('{颜色}')));
196
-
197
- // 年龄测试OK
198
- $.log.debug('\n=== 年龄测试 ===');
199
- const AGE_TESTS = ['年方二八', '28岁了', '十八岁了'];
200
- AGE_TESTS.forEach(age => $.log.debug(age.matchs('{年龄}')));
201
-
202
- str = '/user';
203
- $.log.debug(str.matchs('/user'));
204
-
205
- str = '/user/1';
206
- $.log.debug(str.matchs('/user:id'));
207
-
208
- str = '/user/1';
209
- $.log.debug(str.matchs('/user/*'));
210
-
211
- str = '/user/1';
212
- $.log.debug(str.matchs('/user/'));
213
-
214
- }
215
-
216
- test();