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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值