Documentation ¶
Overview ¶
Package regexp implements a simple regular expression library.
The syntax of the regular expressions accepted is:
regexp: concatenation { '|' concatenation } concatenation: { closure } closure: term [ '*' | '+' | '?' ] term: '^' '$' '.' character '[' [ '^' ] character-ranges ']' '(' regexp ')'
Index ¶
- Variables
- func Match(pattern string, b []byte) (matched bool, error os.Error)
- func MatchString(pattern string, s string) (matched bool, error os.Error)
- func QuoteMeta(s string) string
- type Regexp
- func (re *Regexp) AllMatches(b []byte, n int) [][]byte
- func (re *Regexp) AllMatchesIter(b []byte, n int) <-chan []byte
- func (re *Regexp) AllMatchesString(s string, n int) []string
- func (re *Regexp) AllMatchesStringIter(s string, n int) <-chan string
- func (re *Regexp) Execute(b []byte) (a []int)
- func (re *Regexp) ExecuteString(s string) (a []int)
- func (re *Regexp) Match(b []byte) bool
- func (re *Regexp) MatchSlices(b []byte) (a [][]byte)
- func (re *Regexp) MatchString(s string) bool
- func (re *Regexp) MatchStrings(s string) (a []string)
- func (re *Regexp) NumSubexp() int
- func (re *Regexp) ReplaceAll(src, repl []byte) []byte
- func (re *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte
- func (re *Regexp) ReplaceAllString(src, repl string) string
- func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string
Constants ¶
This section is empty.
Variables ¶
var ( ErrInternal = os.NewError("internal error") ErrUnmatchedLpar = os.NewError("unmatched '('") ErrUnmatchedRpar = os.NewError("unmatched ')'") ErrUnmatchedLbkt = os.NewError("unmatched '['") ErrUnmatchedRbkt = os.NewError("unmatched ']'") ErrBadRange = os.NewError("bad range in character class") ErrExtraneousBackslash = os.NewError("extraneous backslash") ErrBadClosure = os.NewError("repeated closure (**, ++, etc.)") ErrBareClosure = os.NewError("closure applies to nothing") ErrBadBackslash = os.NewError("illegal backslash escape") )
Error codes returned by failures to parse an expression.
Functions ¶
func Match ¶
Match checks whether a textual regular expression matches a byte slice. More complicated queries need to use Compile and the full Regexp interface.
func MatchString ¶
MatchString checks whether a textual regular expression matches a string. More complicated queries need to use Compile and the full Regexp interface.
Types ¶
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp is the representation of a compiled regular expression. The public interface is entirely through methods.
func Compile ¶
Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
func MustCompile ¶
MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.
func (*Regexp) AllMatches ¶
AllMatches slices the byte slice b into substrings that are successive matches of the Regexp within b. If n > 0, the function returns at most n matches. Text that does not match the expression will be skipped. Empty matches abutting a preceding match are ignored. The function returns a slice containing the matching substrings.
func (*Regexp) AllMatchesIter ¶
AllMatchesIter slices the byte slice b into substrings that are successive matches of the Regexp within b. If n > 0, the function returns at most n matches. Text that does not match the expression will be skipped. Empty matches abutting a preceding match are ignored. The function returns a channel that iterates over the matching substrings.
func (*Regexp) AllMatchesString ¶
AllMatchesString slices the string s into substrings that are successive matches of the Regexp within s. If n > 0, the function returns at most n matches. Text that does not match the expression will be skipped. Empty matches abutting a preceding match are ignored. The function returns a slice containing the matching substrings.
func (*Regexp) AllMatchesStringIter ¶
AllMatchesStringIter slices the string s into substrings that are successive matches of the Regexp within s. If n > 0, the function returns at most n matches. Text that does not match the expression will be skipped. Empty matches abutting a preceding match are ignored. The function returns a channel that iterates over the matching substrings.
func (*Regexp) Execute ¶
Execute matches the Regexp against the byte slice b. The return value is an array of integers, in pairs, identifying the positions of subslices matched by the expression.
b[a[0]:a[1]] is the subslice matched by the entire expression. b[a[2*i]:a[2*i+1]] for i > 0 is the subslice matched by the ith parenthesized subexpression.
A negative value means the subexpression did not match any element of the slice. An empty array means "no match".
func (*Regexp) ExecuteString ¶
ExecuteString matches the Regexp against the string s. The return value is an array of integers, in pairs, identifying the positions of substrings matched by the expression.
s[a[0]:a[1]] is the substring matched by the entire expression. s[a[2*i]:a[2*i+1]] for i > 0 is the substring matched by the ith parenthesized subexpression.
A negative value means the subexpression did not match any element of the string. An empty array means "no match".
func (*Regexp) Match ¶
Match returns whether the Regexp matches the byte slice b. The return value is a boolean: true for match, false for no match.
func (*Regexp) MatchSlices ¶
MatchSlices matches the Regexp against the byte slice b. The return value is an array of subslices matched by the expression.
a[0] is the subslice matched by the entire expression. a[i] for i > 0 is the subslice matched by the ith parenthesized subexpression.
An empty array means “no match”.
func (*Regexp) MatchString ¶
MatchString returns whether the Regexp matches the string s. The return value is a boolean: true for match, false for no match.
func (*Regexp) MatchStrings ¶
MatchStrings matches the Regexp against the string s. The return value is an array of strings matched by the expression.
a[0] is the substring matched by the entire expression. a[i] for i > 0 is the substring matched by the ith parenthesized subexpression.
An empty array means “no match”.
func (*Regexp) NumSubexp ¶
NumSubexp returns the number of parenthesized subexpressions in this Regexp.
func (*Regexp) ReplaceAll ¶
ReplaceAll returns a copy of src in which all matches for the Regexp have been replaced by repl. No support is provided for expressions (e.g. \1 or $1) in the replacement text.
func (*Regexp) ReplaceAllFunc ¶
ReplaceAllFunc returns a copy of src in which all matches for the Regexp have been replaced by the return value of of function repl (whose first argument is the matched []byte). No support is provided for expressions (e.g. \1 or $1) in the replacement string.
func (*Regexp) ReplaceAllString ¶
ReplaceAllString returns a copy of src in which all matches for the Regexp have been replaced by repl. No support is provided for expressions (e.g. \1 or $1) in the replacement string.
func (*Regexp) ReplaceAllStringFunc ¶
ReplaceAllStringFunc returns a copy of src in which all matches for the Regexp have been replaced by the return value of of function repl (whose first argument is the matched string). No support is provided for expressions (e.g. \1 or $1) in the replacement string.