expression

package module
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2022 License: Apache-2.0 Imports: 3 Imported by: 3

README

expression

Go regular expression wrapper.

Installation

go get -u github.com/coolstina/expression

Features

  • Match IPv4
  • Match internal IPv4
  • Match cellphone Of China
  • Match telephone Of China
  • Match email address
  • Match web domain
  • Match time hour point
  • Match string

How to use?

It's very simple to use, just out of the box, and you can view the documentation through GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegularOfWebDomain    = regexp.MustCompile(`^(http://|https://)?(\d{1,3}(.\d{1,3}){3}|(www.)?[^www.][a-z]+\.[a-z]+)(:\d+)?$`)
	RegularOfIPv4         = regexp.MustCompile(`^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$`)
	RegularOfInternalIPv4 = regexp.MustCompile(`(^127\.)|(^10\.)|(^172\.(1[6-9]|2[0-9]|3[0-1])\.)|(^192\.168\.)`)
	RegularOfCellphone    = regexp.MustCompile(`^(\+86(-|\s)?)?1[3-9][0-9]{9}$`)
	RegularOfTelephone    = regexp.MustCompile(`^(\d{3,4}-)?[1-9][0-9]{4,8}$`)
	RegularOfEmail        = regexp.MustCompile(`^[a-zA-Z0-9]{1,20}(([._\-])?[a-zA-Z0-9]{1,20})*@[a-z0-9]+(\.([a-z]+))+$`)
)

Functions

func IsCellphoneOfChina

func IsCellphoneOfChina(str string) bool

IsCellphoneOfChina regular expression is used to check whether the telephone number is china.

func IsEmail

func IsEmail(str string) bool

IsEmail Use a regular expression to check whether the email address is valid.

func IsIPv4

func IsIPv4(str string) bool

IsIPv4 regular expression is used to check whether the IP address is IPV4.

func IsInternalIPv4

func IsInternalIPv4(str string) bool

IsInternalIPv4 Use a regular expression to check whether the ip address is ipv4.

func IsTelephoneOfChina

func IsTelephoneOfChina(str string) bool

IsTelephoneOfChina regular expression is used to check whether the telephone number is china.

func IsTimeHourPoint added in v0.2.3

func IsTimeHourPoint(str string) bool

IsTimeHourPoint matched time str is time hour point. str similar 00:01/05:28/19:25/23:59

func IsWebDomain added in v0.2.0

func IsWebDomain(str string) bool

IsWebDomain Use a regular expression to check whether the web domain is valid.

func RegularMatchString added in v0.1.2

func RegularMatchString(patten string, s string) (bool, error)

RegularMatchString reports whether the string s contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

func RegularReplaceMatch

func RegularReplaceMatch(patten string, original string, replace string) (string, error)

RegularReplaceMatch Use a regular expression to replace original string to novel string. The underlying call is regexp.Compile(patten).ReplaceAllString() method.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL