CL-PPCRE Unicode Property

193 views Asked by At

I am trying to find a solution to this simple Perl code using the CL-PPCRE Library:

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

I am a newbie to CL-PPCRE and tried:

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

; I got an error saying property #/Space doesn't exists.

How can I execute an equivalent?

2

There are 2 answers

3
dckc On

The perl regexp /\p{Space}/ matches more than just " ". cf \p{} docs

One approach is to just use the \s expression:

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

To use the whole unicode Space class:

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

See Unicode properties in the CL-PPCRE docs.

0
Sim On

The cl-ppcre library does not require you (at least for space) to use any special constant.

(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

will do the trick.