%% Generated by lilypond-book
%% Options: [exampleindent=10.16\mm,indent=0\mm,line-width=160\mm,paper-height=845.047\pt,paper-width=597.508\pt,papersize='(cons (* 597.508 pt) (* 845.047 pt))]
\include "lilypond-book-preamble.ly"


% ****************************************************************
% Start cut-&-pastable-section
% ****************************************************************

#(ly:set-option 'eps-box-padding 3.000000)



\paper {
  #(set-paper-size '(cons (* 597.508 pt) (* 845.047 pt)))
  indent = 0\mm
  line-width = 160\mm
  % offset the left padding, also add 1mm as lilypond creates cropped
  % images with a little space on the right
  line-width = #(- line-width (* mm  3.000000) (* mm 1))
}

\layout {
  
}




% ****************************************************************
% ly snippet:
% ****************************************************************
\sourcefilename "/lilypond-2.26.0/input/regression/other/regex.ly"
\sourcefileline 0
\version "2.25.1"

\header {
  texidoc = "Test the behavior of regular expression
functions."
}

#(assert (equal? "\\*\\+\\$" (ly:regex-quote "*+$")))

#(assert (ly:regex-exec (ly:make-regex (ly:regex-quote "*+$"))
                        "*+$"))

#(let ((regex (ly:make-regex "x(a+)(b*)\\b")))
   (assert (eq? #f (ly:regex-exec regex "aabbcc")))
   (let ((m (ly:regex-exec regex "++xaabb**")))
     (assert (ly:regex-match? m))
     (assert (equal? "xaabb" (ly:regex-match-substring m 0)))
     (assert (equal? "aa" (ly:regex-match-substring m 1)))
     (assert (equal? "bb" (ly:regex-match-substring m 2)))
     (assert (equal? '(2 . 7) (ly:regex-match-positions m 0)))
     (assert (equal? '(3 . 5) (ly:regex-match-positions m 1)))
     (assert (equal? '(5 . 7) (ly:regex-match-positions m 2)))
     (assert (equal? "++" (ly:regex-match-prefix m)))
     (assert (equal? "**" (ly:regex-match-suffix m))))
   (assert (equal? "++xaabbxaabb++" (ly:regex-replace regex "++xaabb++" 0 0)))
   (assert (equal? "++bbaa*++" (ly:regex-replace regex "++xaabb++" 2 1 "*")))
   (assert (equal? "++bbaa++bbbaaa++"
                   (ly:regex-replace
                    regex
                    "++xaabb++xaaabbb++"
                    (lambda (m)
                      (string-append (ly:regex-match-substring m 2)
                                     (ly:regex-match-substring m 1)))))))

#(let* ((regex (ly:make-regex "(?:a(a*)|b(b*))c"))
        (m (ly:regex-exec regex "ac")))
   (assert (equal? "" (ly:regex-match-substring m 1)))
   (assert (not (ly:regex-match-substring m 2)))
   (assert (equal? '(1 . 1) (ly:regex-match-positions m 1)))
   (assert (not (ly:regex-match-positions m 2))))

#(let* ((regex (ly:make-regex "(?:a(a*)|b(b*))(c)"))
        (m (ly:regex-exec regex "ac")))
   (assert (equal? "" (ly:regex-match-substring m 1)))
   (assert (not (ly:regex-match-substring m 2)))
   (assert (equal? '(1 . 1) (ly:regex-match-positions m 1)))
   (assert (not (ly:regex-match-positions m 2))))

#(let ((regex (ly:make-regex "a")))
   (assert (null? (ly:regex-exec->list regex "bbb")))
   (assert (equal? '((0 . 1) (2 . 3) (4 . 5))
                   (map ly:regex-match-positions
                        (ly:regex-exec->list regex "ababab")))))

#(let ((regex (ly:make-regex "aâ")))
   (assert (equal? '("" "" "bb" "") (ly:regex-split regex "aâaâbbaâ")))
   (assert (equal? '("bƀ" "bƀ") (ly:regex-split regex "bƀaâbƀ")))
   (assert (equal? '("") (ly:regex-split regex ""))))

#(let* ((regex (ly:make-regex "(\\W)(\\w)(\\w)(\\w)"))
        (m (ly:regex-exec regex "àçΣabcẞ+Äaèêù")))
   (assert (equal? "+Äaè" (ly:regex-match-substring m)))
   (assert (equal? '(7 . 11) (ly:regex-match-positions m)))
   (assert (equal? "+" (ly:regex-match-substring m 1)))
   (assert (equal? '(7 . 8) (ly:regex-match-positions m 1)))
   (assert (equal? "Ä" (ly:regex-match-substring m 2)))
   (assert (equal? '(8 . 9) (ly:regex-match-positions m 2)))
   (assert (equal? "a" (ly:regex-match-substring m 3)))
   (assert (equal? '(9 . 10) (ly:regex-match-positions m 3)))
   (assert (equal? "è" (ly:regex-match-substring m 4)))
   (assert (equal? '(10 . 11) (ly:regex-match-positions m 4))))

#(let ((regex (ly:make-regex "\\p{L}")))
   (assert (equal? "+1234¡++1234+"
                   (ly:regex-replace regex "a1234¡Äè1234ù" "+"))))



% ****************************************************************
% end ly snippet
% ****************************************************************
