It seems, that the both similar questions do not contain the information I seek.
I don’t get how the mode change works in CL-PPCRE. I tried it with both, embedded modifiers as with the keyword arguments. Can you explain the behaviour to me?
;; From: https://perldoc.perl.org/perlretut
;; "Here are the four possible combinations:
;; $x = "There once was a girlnWho programmed in Perln";
;; $x =~ /^Who/; # doesn't match, "Who" not at start of string
;; $x =~ /^Who/s; # doesn't match, "Who" not at start of string
;; $x =~ /^Who/m; # matches, "Who" at start of second line
;; $x =~ /^Who/sm; # matches, "Who" at start of second line
;; $x =~ /girl.Who/; # doesn't match, "." doesn't match "n"
;; $x =~ /girl.Who/s; # matches, "." matches "n"
;; $x =~ /girl.Who/m; # doesn't match, "." doesn't match "n"
;; $x =~ /girl.Who/sm; # matches, "." matches "n"
(defparameter *x*
"There once was a ladynWho programmed in Lispn")
(ppcre:scan "^Who" *x*) ; => NIL
(ppcre:scan "^(?s)Who" *x*) ; => NIL
(ppcre:scan "^(?m)Who" *x*) ; => NIL -> unfortunately
(ppcre:scan "^(?sm)Who" *x*) ; => NIL -> unfortunately
(ppcre:scan "lady.Who" *x*) ; => 17, 25, #(), #() -> unfortunately
(ppcre:scan "(?s)lady.Who" *x*) ; => 17, 25, #(), #() -> unfortunately
(ppcre:scan "(?m)lady.Who" *x*) ; => 17, 25, #(), #() -> unfortunately
(ppcre:scan "^(?sm)Who" *x*) ; => NIL -> unfortunately
;; Maybe I embedded the modifiers at the wrong place?
(let ((s (ppcre:create-scanner "^Who")))
(ppcre:scan s *x*)) ; => NIL
(let ((s (ppcre:create-scanner "^Who" :single-line-mode t)))
(ppcre:scan s *x*)) ; => NIL
(let ((s (ppcre:create-scanner "^Who" :single-line-mode t)))
(ppcre:scan s *x*)) ; => NIL -> nnnnope
(let ((s (ppcre:create-scanner "lady.Who" :single-line-mode t
:multi-line-mode t)))
(ppcre:scan s *x*)) ; => 17, 25, #(), #() -> At least consistent
(let ((s (ppcre:create-scanner "lady.Who" :single-line-mode t)))
(ppcre:scan s *x*)) ; => 17, 25, #(), #() -> as well
(let ((s (ppcre:create-scanner "lady.Who" :multi-line-mode t)))
(ppcre:scan s *x*)) ; => 17, 25, #(), #() -> as well
(let ((s (ppcre:create-scanner "^Who" :single-line-mode t
:multi-line-mode t)))
(ppcre:scan s *x*)) ; => NIL -> as well
The entry in my problem of understanding was this:
;; So (three let forms just for three explicit outputs):
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil)))
(ppcre:scan s "\n")) ; => NIL -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil)))
(ppcre:scan s "a")) ; => 0, 1, #(), #() -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil)))
(ppcre:scan s "a\n")) ; => NIL -> like above
;; This seems to be the default setting. Now, let's try the opposite:
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode t)))
(ppcre:scan s "\n")) ; => NIL -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode t)))
(ppcre:scan s "a")) ; => 0, 1, #(), #() -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode t)))
(ppcre:scan s "a\n")) ; => NIL -> like above
;; Oops.
;; The documentation:
;; "* Consider using 'single-line mode' if it makes sense for your task.
;; By default (following Perl's practice), a dot means to search for
;; any character except line breaks. In single-line mode a dot searches
;; for any character which in some cases means that large parts of
;; the target can actually be skipped. This can be vastly more
;; efficient for large targets."
;; So, by default :MULTI-LINE-MODE is T. But why there is no effect?
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil :single-line-mode t)))
(ppcre:scan s "\n")) ; => NIL -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil :single-line-mode t)))
(ppcre:scan s "a")) ; => 0, 1, #(), #() -> like above
(let ((s (ppcre:create-scanner "^.$" :multi-line-mode nil :single-line-mode t)))
(ppcre:scan s "a\n")) ; => NIL -> like above
I thank you very much for your hints.
2