Skip to content

Regex for "match everything till eol" matches nothing #231

Open
@Hi-Angel

Description

@Hi-Angel

Describe the bug

Using a pretty simple ".*$" regexp results in No Regex pattern match. That is with noFlags flag that implies multiline: false, so $ should match something.

To Reproduce

Run this code:

module Main where

import Prelude

import Data.Either (Either(..))
import Data.String.Regex.Flags (noFlags)
import Effect (Effect)
import Effect.Console (logShow)
import Parsing (Parser, fail, runParser)
import Parsing.String (regex)

-- The regex from `Parsing` but with more convenient interface.
regexP :: String -> Parser String String
regexP re = case regex re noFlags of
  Left compileError -> fail $ "failed to compile regex: " <> compileError
  Right ret -> ret

s = """My
multiline
string
"""

main :: Effect Unit
main = do
  logShow $ runParser s $ regexP ".*$"

Expected behavior

The parser ought to return string My

Actual behavior

ParseError "No Regex pattern match" (Position { column: 1, index: 0, line: 1 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions