lisp 正则表达式示例

lisp正则表达式可以用多个第三方的包,cliki推荐是cl-ppcre这个包.在代码中写正则表达式可以用cl-interpol这个包方便转义

cl-interpol

如果要匹配一对括号不用cl-interpol,需要写成

"\\(\\)"

借助cl-interpol只需下面的写法

CL-USER> #?R"\(\)"
"\\(\\)"
CL-USER> (cl-ppcre:scan-to-strings #?R"\(\)" "()")
"()"
#()

cl-ppcre

scan-to-string

CL-USER> (cl-ppcre:scan-to-strings #?R"(abc)" "0123abcdef")
"abc"
#("abc")

scan

CL-USER> (cl-ppcre:scan #?R"(abc)" "0123abcdef")
4
7
#(4)
#(7)

do-scans

CL-USER> (cl-ppcre:do-scans (s e rs rg #?R"a(.)c" "a1c a2c a3c a4c")
       (format t "start:~a end:~a reg-start:~a reg-end:~a~%" s e rs rg))
start:0 end:3 reg-start:#(1) reg-end:#(2)
start:4 end:7 reg-start:#(5) reg-end:#(6)
start:8 end:11 reg-start:#(9) reg-end:#(10)
start:12 end:15 reg-start:#(13) reg-end:#(14)
NIL

do-matches-as-strings

CL-USER> (cl-ppcre:do-matches-as-strings (m  #?R"a(.)c" "a1c a2c a3c a4c")
       (format t "~a~%" m))
a1c
a2c
a3c
a4c
NIL
上一篇:C#随机数的使用


下一篇:cocos2d-x自制工具02:AnimatePacker v1.1beta发布!!~!