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

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

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

@dwlnetnl
Copy link
Author

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
Development

No branches or pull requests

3 participants