Loading...
# Get all matches, similar to a global regular expression
(peg/match '(any (+ (<- :a+) 1)) "Hello, world!")
# => @["Hello" "world"]
(peg/match '(any (+ (number :d) 1)) "1A2B3C4D5")
# => @[1 2 3 4 5]
(peg/match '(any (+ (<- :a+) 1)) "12345")
# => @[]
TheLastZombiePlayground# convert a string to an integer
(peg/match '(number :d+) "123")
#=> @[123]
(first (peg/match '(number :d+) "123"))
#=> 123
erichaneyPlayground# more at https://github.com/sogaiu/margaret/tree/master/examples
(peg/match ~{:main (replace (some :header-line)
,(fn [& captures]
(table ;captures)))
:header-line (sequence (capture :header-name) ":"
:s+
(capture :header-value) :crlf)
:header-name (to ":")
:header-value (to :crlf)
:crlf "\r\n"}
(string "Content-Type: text/plain\r\n"
"Content-Length: 1024\r\n"))
# => @[@{"Content-Length" "1024" "Content-Type" "text/plain"}]
sogaiuPlayground(peg/match ~{:main (capture (some :S))}
"hello world")
# => @["hello"]
sogaiuPlayground