Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmannjg committed May 21, 2024
1 parent 54934dd commit 4ed0eb8
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,35 @@ The main documentation is in [Regex.lean](https://bergmannjg.github.io/regex/Reg

## Example

Get captures of "∀ (n : Nat), 0 ≤ n" :

```lean
def Main : IO Unit := do
let re := regex% r"^\p{Math}\s*([^,]+),\s*(\p{Nd})\s*(\p{Math})\s*([a-z])$"
let captures := Regex.captures "∀ (n : Nat), 0 ≤ n" re
IO.println s!"{captures}"
```

Output is

```lean
-- build `re` at compile time
def re := regex% "a?b"
-- searches for the first match in `re`
#eval Regex.captures "b" re
--Output is
--fullMatch: 'b', 0, 1
--groups: #[]
fullMatch: '∀ (n : Nat), 0 ≤ n', 0, 22
groups: #[(some ('(n : Nat)', 4, 13)), (some ('0', 15, 16)),
(some ('≤', 17, 20)), (some ('n', 21, 22))]
```

Api

- *regex%* : notation to build the regular expression at compile time
- *captures* : searches for the first match of the regular expression

Components of regular expression:

- *^* : Assertion Start of line
- *\p{Math}* : match all characters with the Math property
- *\s\** : match white space
- *(\p{Nd})* : capturing group of numeric characters

## Test

The library is tested with the [testdata](./testdata) of Rust Regex crate.
Expand Down

0 comments on commit 4ed0eb8

Please sign in to comment.