regex package:lens-regex-pcre

Builds a traversal over text using a Regex pattern It's a QuasiQuoter which creates a Traversal out of the given regex string. It's equivalent to calling regexing on a Regex created using the re QuasiQuoter. The "real" type is:
regex :: Regex -> IndexedTraversal' Int BS.ByteString Match
It's a traversal which selects Matches; compose it with match or groups to get the relevant parts of your match.
>>> txt = "raindrops on roses and whiskers on kittens"
Search
>>> has ([regex|whisk|]) txt
True
Get matches
>>> txt ^.. [regex|\br\w+|] . match
["raindrops","roses"]
Edit matches
>>> txt & [regex|\br\w+|] . match %~ Char8.intersperse '-' . Char8.map toUpper
"R-A-I-N-D-R-O-P-S on R-O-S-E-S and whiskers on kittens"
Get Groups
>>> txt ^.. [regex|(\w+) on (\w+)|] . groups
[["raindrops","roses"],["whiskers","kittens"]]
Edit Groups
>>> txt & [regex|(\w+) on (\w+)|] . groups %~ reverse
"roses on raindrops and kittens on whiskers"
Get the third match
>>> txt ^? [regex|\w+|] . index 2 . match
Just "roses"
Edit matches
>>> txt & [regex|\br\w+|] . match %~ Char8.intersperse '-' . Char8.map toUpper
"R-A-I-N-D-R-O-P-S on R-O-S-E-S and whiskers on kittens"
Get Groups
>>> txt ^.. [regex|(\w+) on (\w+)|] . groups
[["raindrops","roses"],["whiskers","kittens"]]
Edit Groups
>>> txt & [regex|(\w+) on (\w+)|] . groups %~ reverse
"roses on raindrops and kittens on whiskers"
Get the third match
>>> txt ^? [regex|\w+|] . index 2 . match
Just "roses"
Match integers, Read them into ints, then sort them in-place dumping them back into the source text afterwards.
>>> "Monday: 29, Tuesday: 99, Wednesday: 3" & partsOf ([regex|\d+|] . match . from packedChars . _Show @Int) %~ sort
"Monday: 3, Tuesday: 29, Wednesday: 99"
To alter behaviour of the regex you may wish to pass PCREOptions when compiling it. The default behaviour may seem strange in certain cases; e.g. it operates in 'single-line' mode. You can compile the Regex separately and add any options you like, then pass the resulting Regex into regex; Alternatively can make your own version of the QuasiQuoter with any options you want embedded by using mkRegexQQ.
Builds a traversal over text using a Regex pattern It's a QuasiQuoter which creates a Traversal out of the given regex string. It's equivalent to calling regexing on a Regex created using the re QuasiQuoter. The "real" type is:
regex :: Regex -> IndexedTraversal' Int T.Text Match
It's a traversal which selects Matches; compose it with match or groups to get the relevant parts of your match.
>>> txt = "raindrops on roses and whiskers on kittens"
Search
>>> has ([regex|whisk|]) txt
True
Get matches
>>> txt ^.. [regex|\br\w+|] . match
["raindrops","roses"]
Edit matches
>>> txt & [regex|\br\w+|] . match %~ T.intersperse '-' . T.toUpper
"R-A-I-N-D-R-O-P-S on R-O-S-E-S and whiskers on kittens"
Get Groups
>>> txt ^.. [regex|(\w+) on (\w+)|] . groups
[["raindrops","roses"],["whiskers","kittens"]]
Edit Groups
>>> txt & [regex|(\w+) on (\w+)|] . groups %~ reverse
"roses on raindrops and kittens on whiskers"
Get the third match
>>> txt ^? [regex|\w+|] . index 2 . match
Just "roses"
Edit matches
>>> txt & [regex|\br\w+|] . match %~ T.intersperse '-' . T.toUpper
"R-A-I-N-D-R-O-P-S on R-O-S-E-S and whiskers on kittens"
Get Groups
>>> txt ^.. [regex|(\w+) on (\w+)|] . groups
[["raindrops","roses"],["whiskers","kittens"]]
Edit Groups
>>> txt & [regex|(\w+) on (\w+)|] . groups %~ reverse
"roses on raindrops and kittens on whiskers"
Get the third match
>>> txt ^? [regex|\w+|] . index 2 . match
Just "roses"
Match integers, Read them into ints, then sort them in-place dumping them back into the source text afterwards.
>>> "Monday: 29, Tuesday: 99, Wednesday: 3" & partsOf ([regex|\d+|] . match . unpacked . _Show @Int) %~ sort
"Monday: 3, Tuesday: 29, Wednesday: 99"
To alter behaviour of the regex you may wish to pass PCREOptions when compiling it. The default behaviour may seem strange in certain cases; e.g. it operates in 'single-line' mode. You can compile the Regex separately and add any options you like, then pass the resulting Regex into regex; Alternatively can make your own version of the QuasiQuoter with any options you want embedded by using mkRegexQQ. regex :: Regex -> IndexedTraversal' Int T.Text RBS.Match
An abstract pointer to a compiled PCRE Regex structure The structure allocated by the PCRE library will be deallocated automatically by the Haskell storage manager.
Build a traversal from the provided Regex, this is handy if you're QuasiQuoter averse, or if you already have a Regex object floating around. Also see mkRegexTraversalQQ
Build a traversal from the provided Regex, this is handy if you're QuasiQuoter averse, or if you already have a Regex object floating around. Also see mkRegexTraversalQQ
A lensy interface to regular expressions Please see the README on GitHub at https://github.com/ChrisPenner/lens-regex-pcre#readme
Build a QuasiQuoter just like regex but with the provided PCREOption overrides.