0

我正在尝试使用 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 不存在。

如何执行等效项?

4

2 回答 2

4

perl 正则表达式/\p{Space}/不仅匹配“”。cf \p{} 文档

一种方法是只使用\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 属性

于 2015-03-25T16:03:37.680 回答
-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

会成功的。

于 2015-03-25T14:58:54.050 回答