Skip to content

gchumillas/goparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parser

A library to split any string into smaller tokens based on regular expressions.

Install

Simply execute the following command from a terminal:

go install github.com/gomillas/parser

And then import the library from your project:

import (
	// additional libraries...
	"github.com/gchumillas/go/parser"
)

Example

The following example splits a string into smaller 'words'. Note that regexp ignores initial white spaces:

const regexp = `^\s*(\w+)`
const src = `lorem
ipsum dolor`

m := parser.New(src)
for token, offset := m.Find(regexp); len(token) > 0; token, offset = m.Find(regexp) {
	fmt.Printf("%s (offset: %d)\n", token, offset)
}

// Unordered output:
// lorem (offset: 0)
// ipsum (offset: 6)
// dolor (offset: 12)

About

A GO library to parse strings based on regular expressions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages