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

Regex.find with too lose regex #13

Open
stoivo opened this issue Jan 26, 2017 · 1 comment
Open

Regex.find with too lose regex #13

stoivo opened this issue Jan 26, 2017 · 1 comment

Comments

@stoivo
Copy link

stoivo commented Jan 26, 2017

I was playing with Regex.find and I wanted to find all matches for [a-z0-9] so I wrote the regex ([a-z0-9]*).

I wrote it in Elm and ran it in the repl

> (Regex.find Regex.All (regex "([a-z0-9]*)") "simon er en banan en")
[{ match = "simon", submatches = [Just "simon"], index = 0, number = 1 }]
    : List Regex.Match

So this only return one match. I got some help, and after change the regex to [a-z0-9]+ instead of [a-z0-9]* witch now work like I wanted.

I started to wonder if this is a bug or not? I check what would happen if I tested in the browser.

"simon er en banan en".match(/([a-z0-9]*)/g) 
=> ["simon", "", "er", "", "en", "", "banan", "", "en", ""]

This is not exactly what I wanted but I think the elm method should return the same.

I checked a the source and found that Native/Regex.js#L34 is the line witch stops it from finding more matches. This line was added in https://github.com/elm-lang/core/pull/156 to stop a infinity loop.

@process-bot
Copy link

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

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