summaryrefslogtreecommitdiff
path: root/npc/custom
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-09-20 04:28:50 +0200
committerHaru <haru@dotalux.com>2014-03-17 17:15:02 +0100
commit42da97d7979f5db56d50072dfd7787ebf549ab1b (patch)
tree8946b2b7e5319512b01c0116b20099d263d00196 /npc/custom
parent1cf8ea92f8e8e992617addc371272c78e60df219 (diff)
downloadhercules-42da97d7979f5db56d50072dfd7787ebf549ab1b.tar.gz
hercules-42da97d7979f5db56d50072dfd7787ebf549ab1b.tar.bz2
hercules-42da97d7979f5db56d50072dfd7787ebf549ab1b.tar.xz
hercules-42da97d7979f5db56d50072dfd7787ebf549ab1b.zip
Added regular expression matching script commands and operators
- The script command pcre_match and the operator ~= will return the number of regular expression matches in a given string (roughly equivalent to the php function preg_match or the perl operator =~) - The operator ~! is the opposite of ~= (roughly equivalent to the perl operator !~) - See script_commands and npc/custom/test.txt for more information. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'npc/custom')
-rw-r--r--npc/custom/test.txt17
1 files changed, 16 insertions, 1 deletions
diff --git a/npc/custom/test.txt b/npc/custom/test.txt
index 00f9c376e..6d1c6b49f 100644
--- a/npc/custom/test.txt
+++ b/npc/custom/test.txt
@@ -335,7 +335,7 @@ OnInit:
callsub(OnCheck, "Order of < and <<", .@x);
- // ==, != operators
+ // ==, !=, ~=, ~! operators
.@x = (0 == 0); // true
.@y = (1 == 0); // false
callsub(OnCheck, "== operator", .@x);
@@ -344,6 +344,21 @@ OnInit:
.@y = (1 != 1); // false
callsub(OnCheck, "!= operator", .@x);
callsub(OnCheck, "!= operator", .@y, 0);
+ .@x$ = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
+ "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
+ .@y = (.@x$ ~= "^Lorem.*, ([a-z]*).*(Duis).* ([a-z.]*)$");
+ callsub(OnCheck, "~= operator", .@y, 4);
+ callsub(OnCheck, "~= operator", $@regexmatchcount, 4);
+ if( $@regexmatchcount == 4 ) {
+ callsub(OnCheck, "~= operator", $@regexmatch$[0], .@x$);
+ callsub(OnCheck, "~= operator", $@regexmatch$[1], "quis");
+ callsub(OnCheck, "~= operator", $@regexmatch$[2], "Duis");
+ callsub(OnCheck, "~= operator", $@regexmatch$[3], "laborum.");
+ }
+ .@y = (.@x$ ~! "^Not Lorem.*, ([a-z]*).*(Duis).* ([a-z.]*)$");
+ callsub(OnCheck, "~! operator", .@y);
// Associativity of ==, !=
.@x = (1 == 0 == 0); // (1 == 0) == 0 --> 0 == 0 --> 1