@@ -202,8 +202,11 @@ match p = do
202
202
-- | error message.
203
203
-- |
204
204
-- | The returned parser will try to match the regular expression pattern once,
205
- -- | starting at the current parser position. On success, it will return
206
- -- | the matched substring.
205
+ -- | starting at the current parser position. Note that this implies that an
206
+ -- | expression starting as `^…` (i.e. with the beginning of line) will match the
207
+ -- | current position even in absence of a preceding newline.
208
+ -- |
209
+ -- | On success, the parser will return the matched substring.
207
210
-- |
208
211
-- | If the RegExp `String` is constant then we can assume that compilation will
209
212
-- | always succeed and `unsafeCrashWith` if it doesn’t. If we dynamically
@@ -231,14 +234,24 @@ match p = do
231
234
-- |
232
235
-- | #### Example
233
236
-- |
234
- -- | This example shows how to compile and run the `xMany` parser which will
235
- -- | capture the regular expression pattern `x*`.
237
+ -- | Compiling and running different regex parsers:
236
238
-- |
237
239
-- | ```purescript
238
- -- | case regex "x*" noFlags of
239
- -- | Left compileError -> unsafeCrashWith $ "xMany failed to compile: " <> compileError
240
- -- | Right xMany -> runParser "xxxZ" do
241
- -- | xMany
240
+ -- | example re flags text =
241
+ -- | case regex re flags of
242
+ -- | Left compileError -> unsafeCrashWith $ "xMany failed to compile: " <> compileError
243
+ -- | Right xMany -> runParser text do
244
+ -- | xMany
245
+ -- |
246
+ -- | -- Capturing a string per `x*` regex.
247
+ -- | exampleXMany = example "x*" noFlags "xxxZ"
248
+ -- |
249
+ -- | -- Capturing everything till end of line.
250
+ -- | exampleCharsTillEol = example ".*$" multiline "line1\nline2"
251
+ -- |
252
+ -- | -- Capturing everything till end of string. Note the distinction with
253
+ -- | -- `exampleCharsTillEol`.
254
+ -- | exampleCharsTillEos = example ".*$" dotAll "line1\nline2"
242
255
-- | ```
243
256
-- |
244
257
-- | #### Flags
@@ -249,9 +262,11 @@ match p = do
249
262
-- | regex "x*" (dotAll <> ignoreCase)
250
263
-- | ```
251
264
-- |
252
- -- | The `dotAll`, `unicode`, and `ignoreCase` flags might make sense for
253
- -- | a `regex` parser. The other flags will
254
- -- | probably cause surprising behavior and you should avoid them.
265
+ -- | The `dotAll`, `multiline`, `unicode`, and `ignoreCase` flags might make
266
+ -- | sense for a `regex` parser. In fact, per JS RegExp semantics matching a
267
+ -- | single line boundary in a multiline string requires passing `multiline`.
268
+ -- |
269
+ -- | Other flags will probably cause surprising behavior and should be avoided.
255
270
-- |
256
271
-- | [*MDN Advanced searching with flags*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags)
257
272
regex :: forall m . String -> RegexFlags -> Either String (ParserT String m String )
0 commit comments