Skip to content

Commit

Permalink
Word boundaries etc.: pregexp ~ is for POSIX character classes
Browse files Browse the repository at this point in the history
  • Loading branch information
BostX committed Dec 16, 2023
1 parent fa0891e commit 38b9a17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ TODO Two search patterns means

TODO Find org-mode racket parser / language: https://github.com/tgbugs/laundry

TODO search in subdirectories
For word boundaries etc. see:
https://docs.racket-lang.org/guide/regexp-chars.html#%28part._.P.O.S.I.X_character_classes%29
6 changes: 5 additions & 1 deletion main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ racket main.rkt -p title
racket main.rkt -n -p title
racket main.rkt -np title
racket main.rkt -p rackjure
racket main.rkt -e ./main.rkt -p [[:blank:]]install([[:cntrl:]]|[[:blank:]])
racket main.rkt -e \"/home/bost/der/search-notes/main.rkt /home/bost/der/search-notes/README.md\" -p subdir
"

Expand Down Expand Up @@ -137,8 +138,11 @@ racket main.rkt -e \"/home/bost/der/search-notes/main.rkt /home/bost/der/search-
(colorize colorize-matches? display-fn
(cdr matches) (cdr patterns)))]))

;; - For regexp vs. pregexp - the same must be used also in notes.rkt;
;; - In contrary to the regexp-defining string in the notes.rkt no '.*' must
;; be used.
(define regexp-split-match
(regexp (format "(?~a:~a)" (case-sensitivity-params) (pattern-param))))
(pregexp (format "(?~a:~a)" (case-sensitivity-params) (pattern-param))))

(define colorize-matches? (colorize-matches-param))

Expand Down
12 changes: 11 additions & 1 deletion notes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@
#`(begin
'(#,@((compose
(curry map bytes->string/utf-8)
#;
(lambda (s)
(display (format "matches: ~a\n" s))
s)
(curry filter
(curry regexp-match
#;#px"^.*labor.*" #;#rx"^.*labor.*"
((compose
regexp
;; See also the regexp-split-match in the main.rkt
#;
(lambda (s)
(display (format "notes: ~a\n" s))
s)
;; regexp ;; #rx
pregexp ;; #px - posix
#;
(lambda (s)
(display (format "notes: ~a\n" s))
Expand Down

0 comments on commit 38b9a17

Please sign in to comment.