diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2010-12-29 16:26:25 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2010-12-29 16:26:25 +0100 |
commit | d3148268857e01116d5d3c99ac0a43bc6a54b13c (patch) | |
tree | 6ae273025ef73942c0ac748e715a7f281a6af114 /samples/regexp.lua | |
download | lspipat-d3148268857e01116d5d3c99ac0a43bc6a54b13c.tar.gz |
Diffstat (limited to 'samples/regexp.lua')
-rw-r--r-- | samples/regexp.lua | 26 |
1 files changed, 26 insertions, 0 deletions
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, ".")) |