commonregex

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2018 License: MIT Imports: 1 Imported by: 18

README



CommonRegex

A collection of often used regular expressions for Go




Inspired by CommonRegex

This is a collection of often used regular expressions. It provides these as simple functions for getting the matched strings corresponding to specific patterns.

Installation

go get github.com/mingrammer/commonregex

Usage

import (
    cregex "github.com/mingrammer/commonregex"
)

func main() {
    text := `John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions, You can reach me at (519)-236-2723x341 or get in touch with my associate at harold.smith@gmail.com`

    dateList := cregex.Date(text)
    // ['Jan 9th 2012']
    timeList := cregex.Time(text)
    // ['5:00PM', '4:00']
    linkList := cregex.Links(text)
    // ['www.linkedin.com', 'harold.smith@gmail.com']
    phoneList := cregex.PhonesWithExts(text)  
    // ['(519)-236-2723x341']
    emailList := cregex.Emails(text)
    // ['harold.smith@gmail.com']
}

Features

  • Date
  • Time
  • Phone
  • Phones with exts
  • Link
  • Email
  • IPv4
  • IPv6
  • IP
  • Ports without well-known (not known ports)
  • Price
  • Hex color
  • Credit card
  • VISA credit card
  • MC credit card
  • ISBN 10/13
  • BTC address
  • Street address
  • Zip code
  • Po box
  • SSN
  • MD5
  • SHA1
  • SHA256
  • GUID
  • MAC address
  • IBAN
  • Git Repository

Thanks to ❤

License

FOSSA Status

Documentation

Index

Constants

View Source
const (
	DatePattern           = `` /* 461-byte string literal not displayed */
	TimePattern           = `(?i)\d{1,2}:\d{2} ?(?:[ap]\.?m\.?)?|\d[ap]\.?m\.?`
	PhonePattern          = `` /* 133-byte string literal not displayed */
	PhonesWithExtsPattern = `` /* 273-byte string literal not displayed */
	LinkPattern           = `` /* 176-byte string literal not displayed */
	EmailPattern          = `(?i)([A-Za-z0-9!#$%&'*+\/=?^_{|.}~-]+@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)`
	IPv4Pattern           = `(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)`
	IPv6Pattern           = `` /* 1224-byte string literal not displayed */
	IPPattern             = IPv4Pattern + `|` + IPv6Pattern
	NotKnownPortPattern   = `6[0-5]{2}[0-3][0-5]|[1-5][\d]{4}|[2-9][\d]{3}|1[1-9][\d]{2}|10[3-9][\d]|102[4-9]`
	PricePattern          = `[$]\s?[+-]?[0-9]{1,3}(?:(?:,?[0-9]{3}))*(?:\.[0-9]{1,2})?`
	HexColorPattern       = `(?:#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3}))`
	CreditCardPattern     = `(?:(?:(?:\d{4}[- ]?){3}\d{4}|\d{15,16}))`
	VISACreditCardPattern = `4\d{3}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}`
	MCCreditCardPattern   = `5[1-5]\d{2}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}`
	BtcAddressPattern     = `[13][a-km-zA-HJ-NP-Z1-9]{25,34}`
	StreetAddressPattern  = `` /* 149-byte string literal not displayed */
	ZipCodePattern        = `\b\d{5}(?:[-\s]\d{4})?\b`
	PoBoxPattern          = `(?i)P\.? ?O\.? Box \d+`
	SSNPattern            = `(?:\d{3}-\d{2}-\d{4})`
	MD5HexPattern         = `[0-9a-fA-F]{32}`
	SHA1HexPattern        = `[0-9a-fA-F]{40}`
	SHA256HexPattern      = `[0-9a-fA-F]{64}`
	GUIDPattern           = `[0-9a-fA-F]{8}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{12}`
	ISBN13Pattern         = `(?:[\d]-?){12}[\dxX]`
	ISBN10Pattern         = `(?:[\d]-?){9}[\dxX]`
	MACAddressPattern     = `(([a-fA-F0-9]{2}[:-]){5}([a-fA-F0-9]{2}))`
	IBANPattern           = `[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z\d]?){0,16}`
	GitRepoPattern        = `((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?`
)

Regular expression patterns

Variables

Compiled regular expressions

Functions

func BtcAddresses

func BtcAddresses(text string) []string

BtcAddresses finds all bitcoin addresses

func CreditCards

func CreditCards(text string) []string

CreditCards finds all credit card numbers

func Date

func Date(text string) []string

Date finds all date strings

func Emails

func Emails(text string) []string

Emails finds all email strings

func GUIDs

func GUIDs(text string) []string

GUIDs finds all GUID strings

func GitRepos

func GitRepos(text string) []string

GitRepos finds all git repository addresses which have protocol prefix

func HexColors

func HexColors(text string) []string

HexColors finds all hex color values

func IBANs

func IBANs(text string) []string

IBANs finds all IBAN strings

func IPs

func IPs(text string) []string

IPs finds all IP addresses (both IPv4 and IPv6)

func IPv4s

func IPv4s(text string) []string

IPv4s finds all IPv4 addresses

func IPv6s

func IPv6s(text string) []string

IPv6s finds all IPv6 addresses

func ISBN10s

func ISBN10s(text string) []string

ISBN10s finds all ISBN10 strings

func ISBN13s

func ISBN13s(text string) []string

ISBN13s finds all ISBN13 strings

func Links(text string) []string

Links finds all link strings

func MACAddresses

func MACAddresses(text string) []string

MACAddresses finds all MAC addresses

func MCCreditCards

func MCCreditCards(text string) []string

MCCreditCards finds all MasterCard credit card numbers

func MD5Hexes

func MD5Hexes(text string) []string

MD5Hexes finds all MD5 hex strings

func NotKnownPorts

func NotKnownPorts(text string) []string

NotKnownPorts finds all not-known port numbers

func Phones

func Phones(text string) []string

Phones finds all phone numbers

func PhonesWithExts

func PhonesWithExts(text string) []string

PhonesWithExts finds all phone numbers with ext

func PoBoxes

func PoBoxes(text string) []string

PoBoxes finds all po-box strings

func Prices

func Prices(text string) []string

Prices finds all price strings

func SHA1Hexes

func SHA1Hexes(text string) []string

SHA1Hexes finds all SHA1 hex strings

func SHA256Hexes

func SHA256Hexes(text string) []string

SHA256Hexes finds all SHA256 hex strings

func SSNs

func SSNs(text string) []string

SSNs finds all SSN strings

func StreetAddresses

func StreetAddresses(text string) []string

StreetAddresses finds all street addresses

func Time

func Time(text string) []string

Time finds all time strings

func VISACreditCards

func VISACreditCards(text string) []string

VISACreditCards finds all VISA credit card numbers

func ZipCodes

func ZipCodes(text string) []string

ZipCodes finds all zip codes

Types

This section is empty.

Jump to

Keyboard shortcuts

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