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

Different behaviour for re-matches #805

Open
jfacorro opened this issue Jun 7, 2021 · 0 comments
Open

Different behaviour for re-matches #805

jfacorro opened this issue Jun 7, 2021 · 0 comments
Labels

Comments

@jfacorro
Copy link
Member

jfacorro commented Jun 7, 2021

Describe the bug
The implementation of re-matches and re-find for Clojure in the JVM relies on the underlying java.util.regex.Matcher class which provides the matches() and find() methods.

The main difference between these two is that matches() tries to match the whole string. The Clojerl implementation for re-matches makes use of re-find and checks that the first item returned is equal to the provided string (i.e. the whole input was matched). This approach works fine for most regular expressions, but there are cases where this does not work.

To Reproduce

(re-matches #"(.*)\$(.*?)(__[0-9]+)?" "user$eval140$fn__141")

Expected behavior

user=> (re-matches #"(.*)\$(.*?)(__[0-9]+)?" "user$eval140$fn__141")
["user$eval140$fn__141" "user$eval140" "fn" "__141"]

Actual behavior

clje.user=> (re-matches #"(.*)\$(.*?)(__[0-9]+)?" "user$eval140$fn__141")
nil

We can get the same behaviour in Clojerl if we add a $ at the end of the regex above:

clje.user=> (re-matches #"(.*)\$(.*?)(__[0-9]+)?$" "user$eval140$fn__141")
["user$eval140$fn__141" "user$eval140" "fn" "__141"]

But this is not what users should need to do.

Context

  • clojerl version (tag/sha): 0.7.1-69-g74b5d70
@jfacorro jfacorro added the bug label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant