Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
f41ffc2b
Commit
f41ffc2b
authored
Feb 04, 2013
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
regexp: add (*Regexp).Longest
Fixes #3696. R=rsc CC=golang-dev
https://golang.org/cl/7133051
parent
1d9f67da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/pkg/regexp/exec_test.go
src/pkg/regexp/exec_test.go
+14
-0
src/pkg/regexp/regexp.go
src/pkg/regexp/regexp.go
+8
-0
No files found.
src/pkg/regexp/exec_test.go
View file @
f41ffc2b
...
...
@@ -706,3 +706,17 @@ func BenchmarkMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
func
BenchmarkMatchHard_32K
(
b
*
testing
.
B
)
{
benchmark
(
b
,
hard
,
32
<<
10
)
}
func
BenchmarkMatchHard_1M
(
b
*
testing
.
B
)
{
benchmark
(
b
,
hard
,
1
<<
20
)
}
func
BenchmarkMatchHard_32M
(
b
*
testing
.
B
)
{
benchmark
(
b
,
hard
,
32
<<
20
)
}
func
TestLongest
(
t
*
testing
.
T
)
{
re
,
err
:=
Compile
(
`a(|b)`
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
g
,
w
:=
re
.
FindString
(
"ab"
),
"a"
;
g
!=
w
{
t
.
Errorf
(
"first match was %q, want %q"
,
g
,
w
)
}
re
.
Longest
()
if
g
,
w
:=
re
.
FindString
(
"ab"
),
"ab"
;
g
!=
w
{
t
.
Errorf
(
"longest match was %q, want %q"
,
g
,
w
)
}
}
src/pkg/regexp/regexp.go
View file @
f41ffc2b
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment