CL-PPCRE Unicode属性

时间:2015-03-25 14:41:47

标签: common-lisp cl-ppcre

我正在尝试使用CL-PPCRE库找到这个简单Perl代码的解决方案:

if (/\p{Space}/){
  print "This string has some spaces\n";
}

我是CL-PPCRE的新手并尝试过:

   (scan "\\p{\\#Space}" "The String has some white spaces")

我收到一个错误,说属性#/ Space不存在。

如何执行等效?

2 个答案:

答案 0 :(得分:3)

perl regexp /\p{Space}/不仅仅匹配" &#34 ;. cf \p{} docs

一种方法是使用\s表达式:

(cl-ppcre:scan "\\s" (format nil "hi~Cthere" #\return))

使用整个unicode Space类:

(ql:quickload :cl-unicode)
(cl-ppcre:scan "\\p{Space}" (format nil "hi~Cthere" #\return))

请参阅CL-PPCRE文档中的Unicode properties

答案 1 :(得分:-1)

cl-ppcre库不需要你(至少是空间)使用任何特殊常量。

(if (cl-ppcre:scan " " "alle meine entchen")
    (FORMAT T "Does have spaces~%")
    (FORMAT T "Does not have spaces~%"))
> Does have spaces

(if (cl-ppcre:scan " " "allemeineentchen")
    (FORMAT T "Does have spaces~%")
    (FORMAT T "Does not have spaces~%"))
> Does not have spaces

会做到这一点。