PasteRack.org
Paste # 45301
2023-04-10 01:44:55

Fork as a new paste.

Paste viewed 1292 times.


Embed:

  1. #lang racket
  2.  
  3. (define tests  (list " : text 1234"
  4.                      " . text 1234"
  5.                      " , text 1234"
  6.                      " _ text 1234"
  7.                      ))
  8.  
  9. (define patterns (list #px"[:alpha:]"
  10.                        #px"[A-Za-z]"
  11.                        #px"[:alnum:]"
  12.                        #px"\\w"
  13.                        #px"[A-Za-z0-9]"
  14.                        #px"[:digit:]"
  15.                        #px"\\d"
  16.                        #px"[:xdigit:]"
  17.                        #px"[A-Fa-f0-9]"
  18.                        ))
  19.  
  20. (for [(p (in-list patterns))]
  21.   (println p)
  22.   (for [(t (in-list tests))]
  23.     (printf "~v -> ~v~n" t (regexp-match p t ))
  24.     ))

=>

#px"[:alpha:]"

" : text 1234" -> '(":")

" . text 1234" -> #f

" , text 1234" -> #f

" _ text 1234" -> #f

#px"[A-Za-z]"

" : text 1234" -> '("t")

" . text 1234" -> '("t")

" , text 1234" -> '("t")

" _ text 1234" -> '("t")

#px"[:alnum:]"

" : text 1234" -> '(":")

" . text 1234" -> #f

" , text 1234" -> #f

" _ text 1234" -> #f

#px"\\w"

" : text 1234" -> '("t")

" . text 1234" -> '("t")

" , text 1234" -> '("t")

" _ text 1234" -> '("_")

#px"[A-Za-z0-9]"

" : text 1234" -> '("t")

" . text 1234" -> '("t")

" , text 1234" -> '("t")

" _ text 1234" -> '("t")

#px"[:digit:]"

" : text 1234" -> '(":")

" . text 1234" -> '("t")

" , text 1234" -> '("t")

" _ text 1234" -> '("t")

#px"\\d"

" : text 1234" -> '("1")

" . text 1234" -> '("1")

" , text 1234" -> '("1")

" _ text 1234" -> '("1")

#px"[:xdigit:]"

" : text 1234" -> '(":")

" . text 1234" -> '("t")

" , text 1234" -> '("t")

" _ text 1234" -> '("t")

#px"[A-Fa-f0-9]"

" : text 1234" -> '("e")

" . text 1234" -> '("e")

" , text 1234" -> '("e")

" _ text 1234" -> '("e")