@@ -31,7 +31,6 @@ import "Text.Regex.TDFA"
31
31
32
32
= Basics
33
33
34
- @
35
34
>>> let emailRegex = "[a-zA-Z0-9+._-]+\\@[-a-zA-Z]+\\.[a-z]+"
36
35
>>> "my email is [email protected] " =~ emailRegex :: Bool
37
36
True
45
44
>>> "#@invalid.com" =~ emailRegex :: Bool
46
45
False
47
46
47
+ @
48
48
/-- non-monadic/
49
49
λ> \<to-match-against\> '=~' \<regex\>
50
50
@@ -69,66 +69,61 @@ type you want, especially if you're trying things out at the REPL.
69
69
@
70
70
/-- returns empty string if no match/
71
71
a '=~' b :: String /-- or ByteString, or Text.../
72
+ @
72
73
73
74
>>> "alexis-de-tocqueville" =~ "[a-z]+" :: String
74
75
"alexis"
75
76
76
77
>>> "alexis-de-tocqueville" =~ "[0-9]+" :: String
77
78
""
78
79
79
- @
80
-
81
80
== Check if it matched at all
82
81
83
82
@
84
83
a '=~' b :: Bool
84
+ @
85
85
86
86
>>> "alexis-de-tocqueville" =~ "[a-z]+" :: Bool
87
87
True
88
88
89
- @
90
-
91
89
== Get first match + text before/after
92
90
93
91
@
94
92
/-- if no match, will just return whole/
95
93
/-- string in the first element of the tuple/
96
94
a =~ b :: (String, String, String)
95
+ @
97
96
98
97
>>> "alexis-de-tocqueville" =~ "de" :: (String, String, String)
99
98
("alexis-","de","-tocqueville")
100
99
101
100
>>> "alexis-de-tocqueville" =~ "kant" :: (String, String, String)
102
101
("alexis-de-tocqueville","","")
103
102
104
- @
105
-
106
103
== Get first match + submatches
107
104
108
105
@
109
106
/-- same as above, but also returns a list of just submatches./
110
107
/-- submatch list is empty if regex doesn't match at all/
111
108
a '=~' b :: (String, String, String, [String])
109
+ @
112
110
113
111
>>> "div[attr=1234]" =~ "div\\[([a-z]+)=([^]]+)\\]" :: (String, String, String, [String])
114
112
("","div[attr=1234]","",["attr","1234"])
115
113
116
- @
117
-
118
114
== Get /all/ matches
119
115
120
116
@
121
117
/-- can also return Data.Array instead of List/
122
118
'getAllTextMatches' (a '=~' b) :: [String]
119
+ @
123
120
124
121
>>> getAllTextMatches ("john anne yifan" =~ "[a-z]+") :: [String]
125
122
["john","anne","yifan"]
126
123
127
124
>>> getAllTextMatches ("* - . a + z" =~ "[--z]+") :: [String]
128
125
["-",".","a","z"]
129
126
130
- @
131
-
132
127
= Feature support
133
128
134
129
This package does provide captured parenthesized subexpressions.
@@ -160,11 +155,9 @@ just [a]. The character classes like [:alnum:] are supported over
160
155
ASCII only, valid classes are alnum, digit, punct, alpha, graph,
161
156
space, blank, lower, upper, cntrl, print, xdigit, word.
162
157
163
- @
164
158
>>> getAllTextMatches ("john anne yifan" =~ "[[:lower:]]+") :: [String]
165
159
["john","anne","yifan"]
166
160
167
- @
168
161
169
162
This package does not provide "basic" regular expressions. This
170
163
package does not provide back references inside regular expressions.
0 commit comments