Skip to content
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

lookbehind doesn't process newlines or respect start position #2

Closed
burgerrg opened this issue Jan 15, 2020 · 4 comments
Closed

lookbehind doesn't process newlines or respect start position #2

burgerrg opened this issue Jan 15, 2020 · 4 comments

Comments

@burgerrg
Copy link

burgerrg commented Jan 15, 2020

The regular expression '.*(?<!/)'.*' looks for strings with single quotes that have an internal single quote not preceded by a slash.

The following works as expected:

> (pregexp-match "'.*(?<!/)'.*'" "'/'fine'")
#f

Why does this happen?

> (pregexp-match "'.*(?<!/)'.*'" "\n'/'fine'")
("'/'fine'")

But it's fine with a non-newline:

> (pregexp-match "'.*(?<!/)'.*'" "\r'/'fine'")
#f
@burgerrg burgerrg changed the title negative lookbehind and newline interaction lookbehind doesn't process newlines or respect start position Jan 28, 2020
@burgerrg
Copy link
Author

Here are tests that expose the bugs:

  (pregexp-match-positions "(?<=grey)hound"
    "\nthe hound in the picture is not a greyhound")
  ((39 . 44))

  (pregexp-match-positions "(?<!grey)hound"
    "\nthe greyhound in the picture is not a hound")
  ((39 . 44))

  (pregexp-match-positions "(?<=grey)hound"
    "greyhound"
    4)
  #f

  (pregexp-match-positions "(?<!grey)hound"
    "greyhound"
    4)
  ((4 . 9))

@burgerrg
Copy link
Author

See pull request #3

@ds26gte
Copy link
Owner

ds26gte commented Jan 29, 2020

Thank you! I've pushed a rather smaller fix 43fd6da that should address both the issues that you point out.

@burgerrg
Copy link
Author

Looks good, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants