packages feed

lens-regex-pcre 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+18/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.md view
@@ -3,12 +3,19 @@ * NOTE: I don't promise that this is __fast__ yet; * NOTE: currently only supports `Text` but should be generalizable to more string-likes; open an issue if you need it +Based on `pcre-heavy`; so it should support any regexes which it supports.+I'll likely add a way to pass settings in soon; make an issue if you need this :)+ Working with Regexes in Haskell kinda sucks; it's tough to figure out which libs to use, and even after you pick one it's tough to figure out how to use it.  As it turns out; regexes are a very lens-like tool; Traversals allow you to select and alter zero or more matches; traversals can even carry indexes so you know which match or group you're working on.+++Note that all traversals in this library are not techically lawful; the break the 'multi-set'+idempotence law; in reality this isn't usually a problem; but consider yourself warned. Test your code.  Here are a few examples: 
lens-regex-pcre.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 557358c3de76ad43d14cac12d85009470a62f4bbfd0352c727d2d4e89bf80458+-- hash: 99b9284dc756fdcf7fac76739cacfef2e68b962c0addd32d8a322a687fed38c7  name:           lens-regex-pcre-version:        0.1.0.0+version:        0.1.0.1 description:    Please see the README on GitHub at <https://github.com/ChrisPenner/lens-regex-pcre#readme> homepage:       https://github.com/ChrisPenner/lens-regex-pcre#readme bug-reports:    https://github.com/ChrisPenner/lens-regex-pcre/issues
src/Control/Lens/Regex.hs view
@@ -70,6 +70,7 @@ -- > ["_two_","_four_"] -- -- You can edit the traversal to perform a regex replace/substitution+-- -- > > "one _two_ three _four_" & regex [rx|_\w+_|] . match %~ T.toUpper -- > "one _TWO_ three _FOUR_" match :: Traversal' Match T.Text@@ -84,34 +85,42 @@ -- to get the relevant parts of your match. -- -- Getting all matches:+-- -- > > "one _two_ three _four_" ^.. regex [rx|_\w+_|] . match -- > ["_two_","_four_"] -- -- Regex replace/mutation+-- -- > > "one _two_ three _four_" & regex [rx|_\w+_|] . match %~ T.toUpper -- > "one _TWO_ three _FOUR_" -- -- Getting groups with their group index.+-- -- > > "1/2 and 3/4" ^.. regex [rx|(\d+)/(\d+)|] . igroups . withIndex -- > [(0,"1"),(1,"2"),(0,"3"),(1,"4")] -- -- Check for any matches:+-- -- > > has (regex [rx|ne+dle|]) "a needle in a haystack" -- > True -- -- Check for matches which also match a predicate:+-- -- > > has (regex [rx|\w+|] . match . filtered ((> 7) . T.length)) "one word here is loooooooong" -- > True -- -- Get the third match+-- -- > >  "alpha beta charlie delta" ^? (iregex [rx|\w+|] . index 2 . match) -- > Just "charlie" -- -- Replace the third match+-- -- > > "alpha beta charlie delta" & (iregex [rx|\w+|] . index 2 . match) .~ "GAMMA" -- > "alpha beta GAMMA delta" -- -- Match integers, 'Read' them into ints, then sort each match in-place+-- -- > > "Monday: 29, Tuesday: 99, Wednesday: 3" & partsOf' (iregex [rx|\d+|] . match . unpacked . _Show @Int) %~ sort -- > "Monday: 3, Tuesday: 29, Wednesday: 99" regex :: Regex -> Traversal' T.Text Match