regexp

package
v0.1.0-dev.20260314201016 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package regexp provides regular expression operations for the operation graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	op.ProviderBase
	// contains filtered or unexported fields
}

Provider provides regular expression operations with compiled pattern caching. +devlore:access=both

func NewProvider

func NewProvider(ctx op.Context) *Provider

func (*Provider) Find

func (p *Provider) Find(pattern, text string) (string, error)

Find returns the first match of the pattern in the text. Returns an empty string if no match is found.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.

Returns:

  • string: the first match, or empty string if none.
  • error: non-nil if the pattern is invalid.

func (*Provider) FindAll

func (p *Provider) FindAll(pattern, text string, count int) ([]string, error)

FindAll returns all non-overlapping matches of the pattern. The count parameter limits the number of matches; -1 means no limit.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.
  • count: maximum number of matches (-1 for no limit).

Returns:

  • []string: all matches found.
  • error: non-nil if the pattern is invalid.

func (*Provider) FindAllSubmatch

func (p *Provider) FindAllSubmatch(pattern, text string, count int) ([][]string, error)

FindAllSubmatch returns all matches with their submatches. The count parameter limits the number of matches; -1 means no limit.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.
  • count: maximum number of matches (-1 for no limit).

Returns:

  • [][]string: all matches with submatches.
  • error: non-nil if the pattern is invalid.

func (*Provider) FindSubmatch

func (p *Provider) FindSubmatch(pattern, text string) ([]string, error)

FindSubmatch returns the first match and its submatches. Returns nil if no match is found.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.

Returns:

  • []string: the match and submatches, or nil if none.
  • error: non-nil if the pattern is invalid.

func (*Provider) Match

func (p *Provider) Match(pattern, text string) (bool, error)

Match reports whether the text contains any match of the pattern.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.

Returns:

  • bool: true if the pattern matches.
  • error: non-nil if the pattern is invalid.

func (*Provider) Replace

func (p *Provider) Replace(pattern, text, replacement string) (string, error)

Replace replaces all matches of the pattern with the replacement string. The replacement can include $1, $2, etc. for submatch references.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.
  • replacement: the replacement string (supports submatch references).

Returns:

  • string: the text with all matches replaced.
  • error: non-nil if the pattern is invalid.

func (*Provider) ReplaceLiteral

func (p *Provider) ReplaceLiteral(pattern, text, replacement string) (string, error)

ReplaceLiteral replaces all matches with the literal replacement string (no submatch expansion).

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to search.
  • replacement: the literal replacement string.

Returns:

  • string: the text with all matches replaced literally.
  • error: non-nil if the pattern is invalid.

func (*Provider) Split

func (p *Provider) Split(pattern, text string, count int) ([]string, error)

Split splits the text around matches of the pattern. The count parameter limits the number of substrings; -1 means no limit.

Parameters:

  • pattern: the regular expression pattern.
  • text: the string to split.
  • count: maximum number of substrings (-1 for no limit).

Returns:

  • []string: the substrings between matches.
  • error: non-nil if the pattern is invalid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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