Skip to content

Regex.find with too lose regex #13

@stoivo

Description

@stoivo

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.

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