delete PCRE regex

This commit is contained in:
Илья Смышляев 2023-11-01 23:05:25 +03:00
parent e11af6c567
commit db684c6ae7
1 changed files with 15 additions and 8 deletions

View File

@ -2,21 +2,28 @@ package unpackstring
import ( import (
"errors" "errors"
"github.com/GRbit/go-pcre" "regexp"
) )
var ErrInvalidString = errors.New("invalid string") var ErrInvalidString = errors.New("invalid string")
func Unpack(str string) (string, error) { func Unpack(str string) (string, error) {
// Place your code here. // Place your code here.
err := CheckString(str)
re, _ := pcre.Compile(`^\d|\d{2,}|\\(?=\D)|(?=\\)`, pcre.UTF8) if err != nil {
return "", err
res := re.MatchStringWFlags(str, pcre.UTF8)
if res == true {
return "", ErrInvalidString
} }
return "", nil return "", nil
} }
func CheckString(str string) error {
re, _ := regexp.Compile(`^\d|\d{2,}`)
if re.MatchString(str) == true {
return ErrInvalidString
}
return nil
}