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

textfsm

package
v3.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package textfsm reads line-oriented text with a template: a state machine whose rules are regular expressions, in the form Google's TextFSM defined for parsing the output of network devices.

A template declares the values it captures, then the states it moves through. Each state is a list of rules, tried in order against the current line; the first to match assigns its captures and says what happens next: which line to read, whether to emit a record, and which state to enter.

Value Subject (.+)
Value List Body (.*)

Start
  ^${Subject} -> Body

Body
  ^${Body}

The result is a list of records, one per Record action plus the one implied at the end of input, each holding the captures that filled it -- with the line and column each capture came from, which is what places an alert.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capture

type Capture struct {
	Text   string
	Line   int
	Column int
}

A Capture is one piece of text a value took, and where it came from. Line and Column are 1-based, and Column counts runes.

type Record

type Record map[string][]Capture

A Record is one emitted set of captures, keyed by value name. A List value holds every capture; any other holds one.

type Template

type Template struct {
	Values []Value
	// contains filtered or unexported fields
}

A Template is a compiled state machine.

func Parse

func Parse(src string) (*Template, error)

Parse compiles a template.

func (*Template) Run

func (t *Template) Run(text string) ([]Record, error)

Run reads text through the template and returns its records.

type Value

type Value struct {
	Name  string
	Regex string

	// Filldown keeps the last capture across records; Required drops a
	// record the value is missing from; List gathers every capture rather
	// than the last one.
	Filldown bool
	Required bool
	List     bool
}

A Value is one named capture a template fills.

Jump to

Keyboard shortcuts

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