-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex_parsingURL_validationEmail.js
More file actions
64 lines (58 loc) · 2.08 KB
/
Copy pathregex_parsingURL_validationEmail.js
File metadata and controls
64 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function main() {
console.log(
"m d k, m d k, m d k".replace(/(m d k)/g, '$1 a')
);
// Validation checking email
var emailRegex = /([\da-zA-Z_-]+)@([\da-zA-Z_-]+).([\da-zA-Z_-]{2,6})?/;
var emails = [
"addmin@gmail.com",
"addmingmail.com",
"addmi#@ngmail.com",
"addmi#@ngmail.c",
];
function emailValidator(emails, regex){
var result = [];
for (let i = 0; i<emails.length;i++){
if(emails[i].match(emailRegex) != null){
result.push(emails[i] + " --> VALID")
} else {
result.push(emails[i] + " --> false")
}
}
return result;
}
console.log(
emailValidator(emails, emailRegex)
);
// --------------------
// parsing url in node js
// --------------------
// regex with target groups: protocol, domain, zone, port, suburl, hashtag
var urlRegex = /(http|https):\/\/([a-zA-Z-]+).([a-z]{2,}):?([0-9]{4})?((\/[a-zA-Z0-9?=]+){0,})(#[a-zA-Z0-9_-]{0,})?/g;
// here the result will be stored
var result = {};
function parser(
// pattern
match,
// regex target groups:
protocol, domain, zone, port, suburl, hashtag
){
result = {
protocol: protocol,
domain: domain,
zone: zone,
port: port,
suburl: suburl,
hashtag: hashtag
}
return true;
}
// running URL parser
"https://yandex.ru:7890/video/455#hash_tag".replace(urlRegex, parser)
console.dir(
result
);
// --------------------
// END OF parsing url in node js
// --------------------
}());