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/syntax: Enable hand crafted regexp/syntax.Regexp being compiled into a regexp.Regex #18888

Closed
dakerfp opened this issue Feb 1, 2017 · 4 comments

Comments

@dakerfp
Copy link

dakerfp commented Feb 1, 2017

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

NA

What did you do?

I was trying to make an utility library like https://github.com/Miserlou/easy-expressions to
return a Go regexp but I could not use the syntax types defined in the public pkg regexp/syntax

The intended was to have an API like

re, _ := CompileRegex(Digits(), Then("."), Digits())
re.MatchString("100.99")

where re is a *regexp.Regexp that matches "+\d.+\d"

What did you expect to see?

A function to Compile a crafted syntax.Regexp

What did you see instead?

No easy way to do that

Proposal

I could see no easy way to implement it, but most of the required machinery is already in regexp module source.

Is it possible to introduce the functionfunc CompileRegexp(expr syntax.Regexp) (*Regexp, error) in the 1.9 API?

@jimmyfrasche
Copy link
Member

#14078 has a previous rejected proposal to add a Compile func to regexp.

@bradfitz
Copy link
Contributor

bradfitz commented Feb 2, 2017

Also, there's a workaround: https://play.golang.org/p/nQUihJnWOj

@bradfitz bradfitz closed this as completed Feb 2, 2017
@dakerfp
Copy link
Author

dakerfp commented Feb 2, 2017

So, shouldn't be clear in the docs that its usage is discouraged?

@bradfitz
Copy link
Contributor

bradfitz commented Feb 2, 2017

It's not discouraged. We just don't expect people will want to use it so we don't promote it.

@golang golang locked and limited conversation to collaborators Feb 2, 2018
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

4 participants