regex

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

regex is a wrapper for the standard regexp package. It automates the regexp.Compile process for you.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheRegex

func CacheRegex(regex string) error

func CheckRegex

func CheckRegex(regex string) error

func Cleanup

func Cleanup()

func Count

func Count() int

func FindAllString

func FindAllString(src, regex string) ([]string, error)

FindAllString returns a slice of all strings holding the text of the leftmost match in src of the regular expression. If there is no match, the return value is nil. It will be empty if the regular expression successfully matches an empty string.

func FindAllStringSubmatch

func FindAllStringSubmatch(src, regex string) ([][]string, error)

FindAllStringSubmatch returns a slice of a slice of strings holding the text of the leftmost match of the regular expression in src and the matches. A return value of nil indicates no match.

func MatchString

func MatchString(src, regex string) (bool, error)

func ReplaceAllString

func ReplaceAllString(src, regex, replace string) (string, error)

ReplaceAllString returns a copy of src, replacing matches of the regular expression with the replacement string replace. Inside replace, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

Example
package main

import (
	"fmt"
	"simonwaldherr.de/go/golibs/regex"
)

func main() {
	str, _ := regex.ReplaceAllString("FooBaR LoReM IpSuM", "[a-z]", "")
	fmt.Print(str)

}
Output:

FBR LRM ISM

func ReplaceAllStringFunc

func ReplaceAllStringFunc(src, regex string, replace func(s string) string) (string, error)

ReplaceAllStringFunc returns a copy of src in which all matches of the regular expression have been replaced by the return value of function replace applied to the matched substring. The replacement returned by replace is substituted directly, without using Expand.

Types

This section is empty.

Jump to

Keyboard shortcuts

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