package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(?:(?:(public|protected|private)\s+)|(?:(abstract|static)\s+)|(?:(final)\s+)|(?:(volatile|synchronized)\s+)|(?:(native|strictfp)\s+))*([a-zA-Z_][[:alnum:]]+)\s+([a-zA-Z_][[:word:]<>\[\]]+)\s*\(\s*(?:(?:([a-zA-Z_][[:word:]<>\[\]]+)\s+([a-zA-Z_][[:alnum:]]+)\s*)(?:,\s*([a-zA-Z_][[:word:]<>\[\]]+)\s+([a-zA-Z_][[:alnum:]]+)\s*)*)?\)\s*\{`)
var str = `cat
cut
cot
c@t$
c?t
c t?
caut.
caat
cuut!
hello
hello world
lite.ral $ sign
lit\erbl ^ car[a]t
Robert
Bob
Rob
Rick
Rick
lo
lol
loll
lolll
lollll
lolllll
lollllll
lolllllll
lollllllll
lolllllllll
lollllllllll
lolllllllllll
lollllllllllll
while (a < b) { while (c < d) { --d;}; while (b < c) { ++a; --c; } }
10001
18052
19146
<b>thing</a>
+1 555-234-1234 == matches
(654) 999-0234 == matches
+1 (101) 234 9838 == matches
333 444.5555 == matches
111.234-3463 == matches
+1-333-333-3333 == doesn't match (drops the +1)
555 2341234 == doesn't match (missing a separator)
231-1115 == doesn't match (missing an area code)
doowopdoo
shoobeedoobee
doodoodoo
doowop
0
C
a@b.c
bob@bob.bob
steve@steve.co.uk
tom.jones@its.not.unusual
0.0
+.03
-100.3
4.5e5
+0.03e-9
.01e12
.e4
-.e
public static void main(String[] args) {
return;
}
private double thingDoer (int thingA , float thingB) {
while (thingA < thingB) { ++thingA; }
return thingA * thingB;
}
boolean blobber(){
// do blob things
return false;
}
invalidMethodSignature here{
return;
}
anotherInvalidOne(){ return; }`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/