Perl and POSIX compatible regular expressions are mostly similar, but differ in some key aspects, such as fake . This is mentioned here :
POSIX , , . ( Perl, .) , , .
, (foo|foobar). , (, foobarbaz , foo foobar), Perl- (foo), PREIX- (foobar).
( ):
package main
import "fmt"
import "regexp"
func main() {
pattern := "(foo|foobar)"
str := []byte("foobarbaz")
rPCRE, _ := regexp.Compile(pattern)
rPOSIX, _ := regexp.CompilePOSIX(pattern)
matchesPCRE := rPCRE.Find(str)
fmt.Println(string(matchesPCRE))
// prints "foo"
matchesPOSIX := rPOSIX.Find(str)
fmt.Println(string(matchesPOSIX))
// prints "foobar"
}
source
share