0

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?

sigjuice
  • 28,661
  • 12
  • 68
  • 93

2 Answers2

4

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.

dckc
  • 61
  • 4
  • I tried you code and it always produces NIL:(cl-ppcre:scan "\\p{Space}" (format t "hi~Cthere" #\return)) – user2250294 Mar 26 '15 at 15:32
  • I tried the following but it always produces a NIL: (if(cl-ppcre:scan "\\p{Space}" "There is a space here.") (print "Success!")) ;=>NIL if (cl-ppcre:scan "\\p{Digit}" "There is a digit 411")(print "Success!") ;=>nil. {whatever} doesn't seem to be working? – user2250294 Mar 26 '15 at 15:36
  • 1
    note (format t …) prints to `*standard-output*`, (format nil …) writes to a new string. – BRPocock Mar 27 '15 at 20:12
-1

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.

Sim
  • 4,199
  • 4
  • 39
  • 77