v0.0.0-...-1542595 Latest Latest

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

Go to latest
Published: Mar 13, 2024 License: BSD-3-Clause Imports: 13 Imported by: 2



Package regexp implements regular expression search tuned for use in grep-like programs.



This section is empty.


This section is empty.


This section is empty.


type Grep

type Grep struct {
	Regexp *Regexp   // regexp to search for
	Stdout io.Writer // output target
	Stderr io.Writer // error target

	L bool // L flag - print file names only
	C bool // C flag - print count of matches
	N bool // N flag - print line numbers
	H bool // H flag - do not print file names

	Match bool
	// contains filtered or unexported fields


func (*Grep) AddFlags

func (g *Grep) AddFlags()

func (*Grep) File

func (g *Grep) File(name string) []Match

func (*Grep) Reader

func (g *Grep) Reader(r io.Reader, name string) []Match

type Match

type Match struct {
	Path string
	Line int

	// contents of line (Line - 2)
	Ctxp2 string
	// contents of line (Line - 1)
	Ctxp1 string
	// XXX: The following will most likely change after we figure out how
	// to highlight the found text properly :).
	Context string
	// contents of line (Line + 1)
	Ctxn1 string
	// contents of line (Line + 2)
	Ctxn2 string

	// This will be filled in by the source backend
	PathRank float32
	Ranking  float32

type Regexp

type Regexp struct {
	Syntax *syntax.Regexp
	// contains filtered or unexported fields

Regexp is the representation of a compiled regular expression. A Regexp is NOT SAFE for concurrent use by multiple goroutines.

func Compile

func Compile(expr string) (*Regexp, error)

Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against lines of text.

func (*Regexp) Match

func (r *Regexp) Match(b []byte, beginText, endText bool) (end int)

func (*Regexp) MatchString

func (r *Regexp) MatchString(s string, beginText, endText bool) (end int)

func (*Regexp) String

func (re *Regexp) String() string

String returns the source text used to compile the regular expression.

Jump to

Keyboard shortcuts

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