From 42da97d7979f5db56d50072dfd7787ebf549ab1b Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 20 Sep 2013 04:28:50 +0200 Subject: 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 --- npc/custom/test.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'npc/custom/test.txt') 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 -- cgit v1.2.3-60-g2f50