-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex for "match everything till eol" matches nothing #231
Comments
You would need the I'm not really sure where the culprit is here, neither the parsing nor |
Oh actually, immediately after saying that I see it. The parser regex inserts a |
It seems like there's maybe a slight misunderstanding wrt JS RegExp semantics. Without the multiline flag |
Oh, just as I was typing out, you clarified, thank you! Yes, I am not a web-programmer, and in all other languages "multline regex being true" means the opposite, i.e. when you consider whole string more or less as a single line. Okay, I see now, let me try that. |
Sorry, I'm confused here 😅 So, the |
It gets wrapped with |
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
Please see my docs change proposal here |
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
Thanks for the docs change proposal. Also note that if you want “The regex from |
Also, I know this is just your test code, but note that in real code you shouldn't compile the -- 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 |
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
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
Thank you!
In the
Fair warning, because it's a snippet from an actual project. However, I've read the documentation paragraph referred (the discussion about constant vs dynamic generation in particular) but didn't grasp why should't I be compiling it in runtime. Now that I'm experimenting with -- a word at the beginning of line with optional whitespace
topLevelWord :: String -> Parser String String
topLevelWord s = regexP $ "^\\s*" <> s <> "\\b"
…
topLevelWord "SomeFoo" compiler should detect that it's a pure function-chain, so the calls can be replaced with a constant. But it's part of the optimization process, and from what I understand the PureScript designers for some reason relegated optimizations to a separate project. So that means that if (or rather I'm hoping "when") my project comes to production, I'll have to use this separate project to produce the production code. |
That is what he meant, yeah. |
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
Describe the bug
Using a pretty simple
".*$"
regexp results inNo Regex pattern match
. That is withnoFlags
flag that impliesmultiline: false
, so$
should match something.To Reproduce
Run this code:
Expected behavior
The parser ought to return string
My
Actual behavior
The text was updated successfully, but these errors were encountered: