2

I am trying to find all matches in a string with Regex

Regex.find Regex.All (Regex.regex "a*") "aabkdjfaab"

[{ match = "aa", submatches = [], index = 0, number = 1 }] : List Regex.Match

I would expect there be two matches

[{ match = "aa", submatches = [], index = 0, number = 1 }, { match == "aa", submatches = [], index = 9, number = 1 }] : List Regex.Match

however this works if I do

Regex.find Regex.All (Regex.regex "aa") "aabkdjfaab"

what am i missing?

user2167582
  • 5,103
  • 10
  • 50
  • 95
  • This isn't cause by Elm. The seemingly quirky behavior occurs in javascript too (try `/a*/g.exec("aabkdjfaab")`). Perhaps [this answer](https://stackoverflow.com/questions/20922143/regular-expression-with-asterisk-quantifier) can shed some light. Note that `a*` matches the empty string, and you can see all the empty string matches in javascript with `"aabkdjfaab".match(/a*/g)`. – Chad Gilbert Jan 14 '18 at 02:54
  • You probably want `a+` and not `a*`. `a+` gives me `[{ match = "aa", submatches = [], index = 0, number = 1 },{ match = "aa", submatches = [], index = 7, number = 2 }]`. – Dogbert Jan 14 '18 at 10:47

0 Answers0