From d3148268857e01116d5d3c99ac0a43bc6a54b13c Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 29 Dec 2010 16:26:25 +0100 Subject: initial checkin (v0.1 release) --- samples/regexp.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 samples/regexp.lua (limited to 'samples/regexp.lua') diff --git a/samples/regexp.lua b/samples/regexp.lua new file mode 100644 index 0000000..b9b1da2 --- /dev/null +++ b/samples/regexp.lua @@ -0,0 +1,26 @@ +-- Parse IP address using regular expression compiler + +require "lspipat" + + +exp = [=[^([[:digit:]]{1,3})(\.([[:digit:]]{1,3})){3,3}$]=] + +ip1 = RegExp(exp) +print(ip1) + +local captures = {} +ip2 = RegExp(exp, captures) +print(ip2) + +print(spipat.smatch("192.168.0.1", ip1)) +print(spipat.smatch("192.168.000.001", ip1)) +print(spipat.smatch("192.168.0.XXX", ip1)) + +print(spipat.smatch("192.168.0.1", ip2)) + +-- remove captures due to grouping around "." +table.remove(captures, 3) +table.remove(captures, 5) +table.remove(captures, 7) + +print(table.concat(captures, ".")) -- cgit v1.2.3