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

Non-standard index in Regex.Match when using Regex.replace #748

Closed
lazamar opened this Issue Nov 5, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@lazamar

lazamar commented Nov 5, 2016

Matches from Regex.replace have the value <internal structure> in their index key instead of an integer. This value always yields false when compared to other integers and returns NaN when summed to an integer.

This also makes it not possible to compare matches from Regex.find with matches from Regex.replace as the comparison always outputs false.

Examples

Incompatible matches

import Html exposing (text)
import Regex exposing (..)

t = "word word word"

r = regex "\\s\\w+"

matches = find All r t


main =
  text
    <| replace All r (\m -> if List.member m matches then " y" else " n") t

-- Output : word n n
-- Expected : word y y

NaN result in integer operations

Using the same values form r and t.

replace All r (\m -> toString <| m.index + 0) t

-- Output : wordNaNNaN
-- Expected: word49

Always false when compared to other ints

replace All r (\m -> toString <| List.member m.index [0..100]) t

-- Output: wordFalseFalse
-- Expected: wordTrueTrue

Non-standard index in Regex.Match

replace All (regex ".") (\m -> toString m) "a"

-- Output: { match = "a", submatches = [], index = <internal structure>, number = 1 }
-- Expected: { match = "a", submatches = [], index = 0, number = 1 }
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Nov 5, 2016

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.

process-bot commented Nov 5, 2016

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.

@rgrempel

This comment has been minimized.

Show comment
Hide comment
@rgrempel

rgrempel Nov 6, 2016

Contributor

This may have been fixed by #736.

Contributor

rgrempel commented Nov 6, 2016

This may have been fixed by #736.

@lazamar

This comment has been minimized.

Show comment
Hide comment
@lazamar

lazamar Nov 6, 2016

Yes, that is it. Thanks.

lazamar commented Nov 6, 2016

Yes, that is it. Thanks.

@lazamar lazamar closed this Nov 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment