PasteRack.org
Paste # 11951
2023-04-10 02:21:47

Fork as a new paste.

Paste viewed 1336 times.


Embed:

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

=>

#px"[:alpha:]"

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

" . text 1234" -> #f

" , 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")

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

#px"[:alnum:]"

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

" . text 1234" -> #f

" , text 1234" -> #f

" _ text 1234" -> #f

"   text 1234" -> #f

#px"\\w"

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

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

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

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

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

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

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

" . 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")

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

#px"\\d"

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

" . 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")

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

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

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

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

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

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

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