regexps

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 2 Imported by: 2

README

godoc codecov Go Report Card

go-corelibs/regexps - caching regexp compiler and common regexp patterns

regexps is a simple package for common regexp patterns and a caching regexp compilation system.

Installation

> go get github.com/go-corelibs/regexps@latest

Examples

Compile, ClearCache

func main() {
    var err error
    var rx *regexp.Regexp

    // this first call tries to compile the broken pattern
    rx, err = regexps.Compile(`[not a thing`)
    // this second call just returns the prior results for
    // the same broken pattern
    rx, err = regexps.Compile(`[not a thing`)
    // this next call actually compiles a regexp instance
    rx, err = regexps.Compile(`[not] a thing`)
    // trying the same pattern again just returns the prior
    // instance
    rx, err = regexps.Compile(`[not] a thing`)

    // in case clearing the cached results is necessary...
    regexps.ClearCache()
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

View Source
const KeywordPattern = `[a-zA-Z0-9]+?[-'a-zA-Z0-9]*[a-zA-Z0-9]+?|[a-zA-Z0-9]+`

Variables

View Source
var (
	RxNonWord     = regexp.MustCompile(`[^a-zA-Z0-9]`)
	RxEmptySpace  = regexp.MustCompile(`\s+`)
	RxLanguageKey = regexp.MustCompile(`language:(\*|[a-z][-a-zA-Z]+)\s*`)
	RxKeyword     = regexp.MustCompile(`^(` + KeywordPattern + `)$`)
	RxKeywords    = regexp.MustCompile(`\b(` + KeywordPattern + `)\b`)
)
View Source
var (
	RxWord                   = regexp.MustCompile(`\w+`)
	RxQuoteStringsOnly       = regexp.MustCompile(`(?i)^(true|false|-?\d*[.,]?\d*)$`)
	RxParseHtmlTagKeyOnly    = regexp.MustCompile(`^([a-zA-Z][-a-zA-Z0-9]+)$`)
	RxParseHtmlTagKeyValue   = regexp.MustCompile(`^([a-zA-Z][-a-zA-Z0-9]+)=(.+?)$`)
	RxSplitHtmlTagAttributes = regexp.MustCompile(`\s+`)
	RxEmpty                  = regexp.MustCompile(`(?ms)\A\s*\z`)
	RxTmplTags               = regexp.MustCompile(`\{\{.+?}}`)
	RxHash10                 = regexp.MustCompile(`^\s*([a-fA-F0-9]{10})\s*$`)
	RxAtLeastSixDigits       = regexp.MustCompile(`^\s*([0-9]{6,})\s*$`)
)
View Source
var (
	RxKeySlice = regexp.MustCompile(`^([a-zA-Z][-_a-zA-Z0-9]+?[a-zA-Z0-9]*)\[(\d+)\]$`)
)
View Source
var (
	RxTrimCuts = regexp.MustCompile(`^[!/\s]*([^!/].+?)[/\s]*$`)
)

Functions

func ClearCache

func ClearCache()

ClearCache will purge all cached patterns

func Compile

func Compile(pattern string) (rx *regexp.Regexp, err error)

Compile will call regexp.Compile and cache the results and any subsequent calls to Compile with the same patterns return the cached results

Types

This section is empty.

Jump to

Keyboard shortcuts

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