-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
regexp.mon
50 lines (40 loc) · 912 Bytes
/
regexp.mon
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
//
// Simple test of regular expressions
//
//
// Substring match
//
if ( match( "eve", "Steve Kemp" ) ) {
puts( "'Steve Kemp' contains the substring 'eve'\n");
}
//
// Suffix Match
//
if ( match( "emp$", "Steve Kemp" ) ) {
puts( "Suffix-match OK\n");
}
//
// Prefix-match
//
if ( match( "^[A-Z]", "Steve Kemp" ) ) {
puts( "Prefix-match OK\n");
}
//
// IP-address regexp
//
let reg = "([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$";
let out = match(reg, "12.23.21.224");
if (out) {
puts( "We matched an IP address succesfully.\n");
puts( "Captures: ", out[0], ".", out[1], ".", out[2], ".", out[3], "\n");
} else {
puts( "Not true!\n");
}
//
// The same thing using literal a regular expression
//
ip = "192.168.1.1";
if ( ip ~= /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/ ) {
printf( "We matched an IP address succesfully.\n");
printf( "Captures: %s.%s.%s.%s\n", $1, $2, $3, $4 );
}