gitlab.com/evatix-go/core@v1.3.55/regexnew/Create.go (about)

     1  package regexnew
     2  
     3  import "regexp"
     4  
     5  // Create creates regex if not already exist in dictionary.
     6  //
     7  // if any error then doesn't save to map and returns the error
     8  func Create(regularExpressionPattern string) (*regexp.Regexp, error) {
     9  	regex, has := regexMaps[regularExpressionPattern]
    10  
    11  	if has {
    12  		return regex, nil
    13  	}
    14  
    15  	newRegex, err := regexp.Compile(regularExpressionPattern)
    16  
    17  	if err == nil {
    18  		regexMaps[regularExpressionPattern] = newRegex
    19  	}
    20  
    21  	return newRegex, err
    22  }