Help us shape the future of Go! Take the 2026 Go Developer Survey

grep

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package grep implements the `grep`, `egrep`, and `fgrep` built-ins. All three share a single implementation parameterized by the default regex mode (BRE, ERE, fixed).

Flags: -E -F -i -v -n -c -l -L -H -h -r -R -w -x -o -A -B -C -e PAT -f FILE -q -s --include --exclude --color.

Multi-file output sorts filenames. Recursive output uses path/list order from the FS (filename-sorted at each directory level).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() command.Command

New returns the `grep` command (basic regex by default).

func Run

func Run(c *command.Context, args []string, defaultMode Mode) command.Result

Run is the shared entrypoint for grep / egrep / fgrep. `defaultMode` controls how patterns are interpreted when neither -E nor -F is on the command line.

Types

type Mode

type Mode int

Mode is the default regex mode for a grep variant.

const (
	// ModeBasic — BRE. We emulate BRE by treating the pattern as
	// "extended with most metacharacters escaped" — but Go has no
	// real BRE engine. In practice we just compile via Go's RE2
	// (which accepts a strict-ERE superset); BRE-specific quirks
	// like `\{N,M\}` are rare in test fixtures. Matches just-bash.
	ModeBasic Mode = iota
	// ModeExtended — ERE, the Go regexp/syntax.Perl flavor minus
	// PCRE extensions. Same engine as ModeBasic in practice.
	ModeExtended
	// ModeFixed — literal substring matching. Patterns are NEVER
	// compiled as regex; `-i` lowercases both sides.
	ModeFixed
)

Jump to

Keyboard shortcuts

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