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

regexp: [[:xdigit:]] matches some float strings #12900

Closed
dwlnetnl opened this issue Oct 10, 2015 · 2 comments
Closed

regexp: [[:xdigit:]] matches some float strings #12900

dwlnetnl opened this issue Oct 10, 2015 · 2 comments

Comments

@dwlnetnl
Copy link

@dwlnetnl dwlnetnl commented Oct 10, 2015

The documentation in regexp/syntax says that [[:xdigit:]] equals to [0-9A-Fa-f]. But when I execute the code below some non hexadecimal strings are matched.

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`([[:xdigit:]]+),([[:xdigit:]]+)`)

    fmt.Println(re.MatchString("0.0,0.0"))   // true
    fmt.Println(re.MatchString("-0.0,0.0"))  // true
    fmt.Println(re.MatchString("0.0,-0.0"))  // false
    fmt.Println(re.MatchString("-0.0,-0.0")) // false
}

Playground: http://play.golang.org/p/G5NpPo3gtu

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 10, 2015

Yes, it's matching "0,0" in the middle.

Working as intended.

Use ^ and $ around you query if you want to match the full thing. http://play.golang.org/p/xuW71N04-x

@bradfitz bradfitz closed this Oct 10, 2015
@dwlnetnl
Copy link
Author

@dwlnetnl dwlnetnl commented Oct 10, 2015

Thanks for the quick reply!

@golang golang locked and limited conversation to collaborators Oct 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.