dlclark / regexp2

A full-featured regex engine in pure Go based on the .NET engine
MIT License
997 stars 84 forks source link

Regexp is not working for following code. Could you please correct it , if the usage of "regexp2" library is wrong? #16

Closed SaiSasankKhajjayam closed 6 years ago

SaiSasankKhajjayam commented 6 years ago

package main

import ( "fmt" "github.com/dlclark/regexp2" )

func main() { re,_ := regexp2.Compile(Deployment, 0) fmt.Println(re.MatchString(D.*)) // ExpectedOutput: true , ActualOutput: false fmt.Println(re.MatchString(D*)) // ExpectedOutput: true , ActualOutput: false fmt.Println(re.MatchString(Dep)) // ExpectedOutput: true , ActualOutput: false fmt.Println(re.MatchString(Deployment)) // ExpectedOutput: true , ActualOutput: true

}

hachi8833 commented 6 years ago
package main

import (
    "fmt"
    "github.com/dlclark/regexp2"
)

func main() {
    re, _ := regexp2.Compile("D.+nt", 0)
    fmt.Println(re.MatchString("Deployment")) // true
}

Well, I suggest you to avoid using .*; consider using .+ first 😃