@@ -8,10 +8,10 @@ same kind of regular expressions accepted by JavaScript](https://developer.mozil
11−### Find and Replace
11+# Find and Replace
12−@docs contains, find, findN, replace, replaceN
12+@docs contains, find, findAll, replace, replaceAll
15@docs split, splitN
15@docs split, splitN
@@ -40,11 +40,13 @@ caseInsensitive = Native.Regex.caseInsensitive
41{-| Check to see if a Regex is contained in a string.
41{-| Check to see if a Regex is contained in a string.
43− contains (pattern "123") "12345" == True
44+ contains (pattern "123") "12345" == True
44− contains (pattern "b+") "aabbcc" == True
45+ contains (pattern "b+") "aabbcc" == True
46− contains (pattern "789") "12345" == False
47+ contains (pattern "789") "12345" == False
47− contains (pattern "z+") "aabbcc" == False
48+ contains (pattern "z+") "aabbcc" == False
49contains : Regex -> String -> Bool
51contains : Regex -> String -> Bool
50contains = Native.Regex.contains
52contains = Native.Regex.contains
@@ -63,63 +65,69 @@ Here are details on each field:
63 * `number` — if you find many matches, you can think of each one
65 * `number` — if you find many matches, you can think of each one
64 as being labeled with a `number` starting at one. So the first time you
66 as being labeled with a `number` starting at one. So the first time you
65 find a match, that is match `number` one. Second time is match `number` two.
67 find a match, that is match `number` one. Second time is match `number` two.
66− This is useful when paired with `replace` if replacement is dependent on how
68+ This is useful when paired with `replaceAll` if replacement is dependent on how
67 many times a pattern has appeared before.
69 many times a pattern has appeared before.
69type Match = { match : String, submatches : [Maybe String], index : Int, number : Int }
71type Match = { match : String, submatches : [Maybe String], index : Int, number : Int }
71{-| Find all of the matches in a string:
73{-| Find all of the matches in a string:
73− words = find (pattern "\\w+") "hello world"
76+ words = findAll (pattern "\\w+") "hello world"
75− map .match words == ["hello","world"]
78+ map .match words == ["hello","world"]
76− map .index words == [0,6]
79+ map .index words == [0,6]
78− places = find (pattern "[oi]n a (\\w+)") "I am on a boat in a lake."
81+ places = findAll (pattern "[oi]n a (\\w+)") "I am on a boat in a lake."
80− map .match places == ["on a boat", "in a lake"]
83+ map .match places== ["on a boat", "in a lake"]
81− map .submatches places == [ [Just "boat"], [Just "lake"] ]
84+ map .submatches places == [ [Just "boat"], [Just "lake"] ]
83−find : Regex -> String -> [Match]
87+findAll : Regex -> String -> [Match]
84−find = Native.Regex.find
88+findAll = Native.Regex.findAll
86−{-| Same as `find`, but `findN` will quit searching after the Nth match.
90+{-| Same as `findAll`, but `find` will quit searching after the *n<sup>th</sup>* match.
87That means the resulting list has maximum length N, but *it can be shorter*
91That means the resulting list has maximum length N, but *it can be shorter*
88if there are not that many matches in the given string.
92if there are not that many matches in the given string.
90−findN : Int -> Regex -> String -> [Match]
94+find : Int -> Regex -> String -> [Match]
91−findN = Native.Regex.findN
95+find = Native.Regex.find
93{-| Replace all matches. The function from `Match` to `String` lets
97{-| Replace all matches. The function from `Match` to `String` lets
94you use the details of a specific match when making replacements.
98you use the details of a specific match when making replacements.
96− vowels = caseInsensitive (pattern "[aeiou]")
100+```haskell
97− devowel = replace vowels (\_ -> "")
101+ devowel = replaceAll (pattern "[aeiou]") (\_ -> "")
99− devowel "The quick brown fox" == "Th qck brwn fx"
103+ devowel "The quick brown fox" == "Th qck brwn fx"
101− word = pattern "\\w+"
102− reverseWords = replace word (\{match} -> String.reverse match)
105+ reverseWords = replaceAll (pattern "\\w+") (\{match} -> String.reverse match)
104− reverseWords "deliver mined parts" == "reviled denim strap"
107+ reverseWords "deliver mined parts" == "reviled denim strap"
106−replace : Regex -> (Match -> String) -> String -> String
110+replaceAll : Regex -> (Match -> String) -> String -> String
107−replace = Native.Regex.replace
111+replaceAll = Native.Regex.replaceAll
109−{-| Same as `replace`, but `replaceN` will quit after the Nth match.-}
113+{-| Same as `replaceAll`, but `replace` will quit after the *n<sup>th</sup>* match.-}
110−replaceN : Int -> Regex -> (Match -> String) -> String -> String
114+replace : Int -> Regex -> (Match -> String) -> String -> String
111−replaceN = Native.Regex.replaceN
115+replace = Native.Regex.replace
113{-| Split a string, using the regex as the separator.
117{-| Split a string, using the regex as the separator.
115− split (pattern ", ?") "a,b, c, d" == ["a","b","c","d"]
120+ split (pattern " *, *") "a ,b, c,d" == ["a","b","c","d"]
117split : Regex -> String -> [String]
123split : Regex -> String -> [String]
118split = Native.Regex.split
124split = Native.Regex.split
120−{-| Same as `split` but stops after the Nth match.
126+{-| Same as `split` but stops after the *n<sup>th</sup>* match.
122− splitN 1 (pattern ", ?") "a,b,c,d" == ["a","b,c,d"]
129+ splitN 1 (pattern ": *") "tom: 99,90,85" == ["tom","99,90,85"]
124splitN : Int -> Regex -> String -> [String]
132splitN : Int -> Regex -> String -> [String]
125splitN = Native.Regex.splitN
133splitN = Native.Regex.splitN