mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
regexp: add (*Regexp).Longest
Fixes #3696. R=rsc CC=golang-dev https://golang.org/cl/7133051
This commit is contained in:
parent
1d9f67daf0
commit
f41ffc2bf4
2 changed files with 22 additions and 0 deletions
|
|
@ -130,6 +130,14 @@ func CompilePOSIX(expr string) (*Regexp, error) {
|
|||
return compile(expr, syntax.POSIX, true)
|
||||
}
|
||||
|
||||
// Longest sets the match semantics of the regexp to leftmost-longest.
|
||||
// That is, when matching against text, the regexp returns a match that
|
||||
// begins as early as possible in the input (leftmost), and among those
|
||||
// it chooses a match that is as long as possible.
|
||||
func (re *Regexp) Longest() {
|
||||
re.longest = true
|
||||
}
|
||||
|
||||
func compile(expr string, mode syntax.Flags, longest bool) (*Regexp, error) {
|
||||
re, err := syntax.Parse(expr, mode)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue