Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
Matching operator is the interface to use Regular Expression. Note that no escaping characters are required in the regular expression literal.
a =~ /[\t ]+[Ss]omething/;
a !~ /[\t ]+[Ss]omething/;
The operator =~
is to find matched strings. If nothing to be matched, returns false.
If matched, matched strings are returned as structured below.
[
{
string: "whole matched string",
begin: b0,
end: e0
},
{
string: "captured string 1",
begin: b1,
end: e1
},
{
string: "captured string 2",
begin: b2,
end: e2
},
...
]
The operator !~
is used to check if not matched.
If not matched, returns true. Otherwise returns false.
The operator =~
can be used in the loop condition as example below.
while (a =~ /abc/) {
// loop while matched.
}
There is a note when breaking the loop in the half way. If loop is finished incompletely, the regular expression object may not be reset in the next loop. It will be reset well in the next loop when the previous loop is completed after condition is false. The reset will be done when:
a
in the above example, was changed.var a = "a-aaabbb,aabb-baaa,b-bbaaaa";
System.println("%{a}:");
while (group = (a =~ /\w+/)) {
System.println(" found");
var l = group.length();
for (var i = 0; i < l; ++i) {
System.println(" [%2d,%2d) = '%s'"
% group[i].begin
% group[i].end
% group[i].string);
}
}
a-aaabbb,aabb-baaa,b-bbaaaa:
found
[ 0, 1) = 'a'
found
[ 2, 8) = 'aaabbb'
found
[ 9,13) = 'aabb'
found
[14,18) = 'baaa'
found
[19,20) = 'b'
found
[21,27) = 'bbaaaa'
/=.../
var a = "a=aaabbb,aabb=baaa,b=bbaaaa";
System.println("%{a}:");
while (group = (a =~ /=\w+/)) {
System.println(" found");
var l = group.length();
for (var i = 0; i < l; ++i) {
System.println(" [%2d,%2d) = '%s'"
% group[i].begin
% group[i].end
% group[i].string);
}
}
a=aaabbb,aabb=baaa,b=bbaaaa:
found
[ 1, 8) = '=aaabbb'
found
[13,18) = '=baaa'
found
[20,27) = '=bbaaaa'
%m(...)
var a = "abbb/aabbbaaa/bbbaa/aa";
System.println("%{a}:");
while (group = (a =~ %m(a+/))) {
System.println(" found");
var l = group.length();
for (var i = 0; i < l; ++i) {
System.println(" [%2d,%2d) = '%s'"
% group[i].begin
% group[i].end
% group[i].string);
}
}
abbb/aabbbaaa/bbbaa/aa:
found
[10,14) = 'aaa/'
found
[17,20) = 'aa/'