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: accepts x{,3} but different from x{0,3} ? #3407

Closed
rsc opened this issue Mar 27, 2012 · 1 comment
Closed

regexp: accepts x{,3} but different from x{0,3} ? #3407

rsc opened this issue Mar 27, 2012 · 1 comment
Assignees

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Mar 27, 2012

http://play.golang.org/p/sgdJPamWRd

package main

import "regexp"

var r1 = regexp.MustCompile("x{0,3}")
var r2 = regexp.MustCompile("x{,3}")

func main() {
    println(r1.MatchString(""), r2.MatchString(""))
}

prints 'true false' but I expected 'true true'.

It is entirely possible that I have forgotten what x{,3} means,
but I thought it meant x{0,3}.  It is not listed on
http://code.google.com/p/re2/wiki/Syntax, so maybe
it should be a syntax error?
@rsc
Copy link
Contributor Author

@rsc rsc commented Mar 27, 2012

Comment 1:

Regexps do not allow writing {,n} for {0,n},
but there are no syntax errors in { } operations.
Something that doesn't fit the syntax is treated
as literal text, so x{,n} is the same as x\{,n\}. 
So the program is working as "intended".

Status changed to WorkingAsIntended.

@rsc rsc self-assigned this Mar 27, 2012
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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
2 participants
You can’t perform that action at this time.