Skip to content

Commit a7eaab0

Browse files
committed
Document that for "usual" regex behavior multiline is required
Regular expression users typically expect that matching a `$` in a multiline string would match the end of current line and not the end of the string past many lines. This is default behavior in pretty much every regexp engine: `grep`, `perl`, text editors, you name it… So it is fair to expect such expectation, so warn a user about necessity to pass `multiline` Fixes: purescript-contrib#231
1 parent c38e6ea commit a7eaab0

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Diff for: src/Parsing/String.purs

+21-9
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,24 @@ match p = do
231231
-- |
232232
-- | #### Example
233233
-- |
234-
-- | This example shows how to compile and run the `xMany` parser which will
235-
-- | capture the regular expression pattern `x*`.
234+
-- | Compiling and running different regex parsers:
236235
-- |
237236
-- | ```purescript
238-
-- | case regex "x*" noFlags of
239-
-- | Left compileError -> unsafeCrashWith $ "xMany failed to compile: " <> compileError
240-
-- | Right xMany -> runParser "xxxZ" do
241-
-- | xMany
237+
-- | example re flags text =
238+
-- | case regex re flags of
239+
-- | Left compileError -> unsafeCrashWith $ "xMany failed to compile: " <> compileError
240+
-- | Right xMany -> runParser text do
241+
-- | xMany
242+
-- |
243+
-- | -- Capturing a string per `x*` regex.
244+
-- | exampleXMany = example "x*" noFlags "xxxZ"
245+
-- |
246+
-- | -- Capturing everything till end of line.
247+
-- | exampleCharsTillEol = example ".*$" multiline "line1\nline2"
248+
-- |
249+
-- | -- Capturing everything till end of string. Note the distinction with
250+
-- | -- `exampleCharsTillEol`.
251+
-- | exampleCharsTillEos = example ".*$" (dotAll <> multiline) "line1\nline2"
242252
-- | ```
243253
-- |
244254
-- | #### Flags
@@ -249,9 +259,11 @@ match p = do
249259
-- | regex "x*" (dotAll <> ignoreCase)
250260
-- | ```
251261
-- |
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.
262+
-- | The `dotAll`, `multiline`, `unicode`, and `ignoreCase` flags might make
263+
-- | sense for a `regex` parser. In fact, per JS RegExp semantics matching a
264+
-- | single line boundary in a multiline string requires passing `multiline`.
265+
-- |
266+
-- | Other flags will probably cause surprising behavior and should be avoided.
255267
-- |
256268
-- | [*MDN Advanced searching with flags*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags)
257269
regex :: forall m. String -> RegexFlags -> Either String (ParserT String m String)

0 commit comments

Comments
 (0)