Skip to content
/ re Public

re combines regular expression matching with fmt.Scan like extraction of sub-matches into caller-supplied objects.

License

Notifications You must be signed in to change notification settings

ghemawat/re

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

re package

Package re combines regular expression matching with fmt.Scan like extraction of sub-matches into caller-supplied objects. Pointers to variables can be passed as extra arguments to re.Scan. These variables are filled in with regular expression sub-matches. The sub-matches are parsed appropriately based on the type of the variable. E.g., if a *int is passed in, the sub-match is parsed as a number (and overflow is detected).

For example, the host and port portions of a URL can be extracted as follows:

var host string
var port int
reg := regexp.MustCompile(`^https?://([^/:]+):(\d+)/`)
if err := re.Scan(reg, url, &host, &port); err == nil {
	Process(host, port)
}

A "func([]byte) error" can also be passed in as an extra argument to provide custom parsing.

Installation

go get github.com/ghemawat/re

See godoc for further documentation and examples.

About

re combines regular expression matching with fmt.Scan like extraction of sub-matches into caller-supplied objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages