re

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 6 Imported by: 0

README

re

re defines regular expression functions, it's intended to be a drop-in subset of Python's re module for Starlark.

Functions

compile(pattern) Pattern

Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods.

Parameters
name type description
pattern string regular expression pattern string
search(pattern,string,flags=0)

Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding match object. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.

Parameters
name type description
pattern string regular expression pattern string
string string input string to search
flags int integer flags to control regex behaviour. reserved for future use
findall(pattern, text, flags=0)

Returns all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.

Parameters
name type description
pattern string regular expression pattern string
text string string to find within
flags int integer flags to control regex behaviour. reserved for future use
split(pattern, text, maxsplit=0, flags=0)

Split text by the occurrences of pattern. If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting list. If maxsplit is nonzero, at most maxsplit splits occur, and the remainder of the string is returned as the final element of the list.

Parameters
name type description
pattern string regular expression pattern string
text string input string to split
maxsplit int maximum number of splits to make. default 0 splits all matches
flags int integer flags to control regex behaviour. reserved for future use
sub(pattern, repl, text, count=0, flags=0)

Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if it is a string, any backslash escapes in it are processed. That is, \n is converted to a single newline character, \r is converted to a carriage return, and so forth.

Parameters
name type description
pattern string regular expression pattern string
repl string string to replace matches with
text string input string to replace
count int number of replacements to make, default 0 means replace all matches
flags int integer flags to control regex behaviour. reserved for future use
match(pattern, string, flags=0)

If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding match string tuple. Return None if the string does not match the pattern

Parameters
name type description
pattern string regular expression pattern string
string string input string to match

Types

Pattern

Methods

match(text, flags=0)
findall(text, flags=0)
split(text, maxsplit=0, flags=0)
sub(repl, text, count=0, flags=0)

Documentation

Overview

Package re defines regular expression functions, it's intended to be a drop-in subset of Python's re module for Starlark.

Migrated from: https://github.com/qri-io/starlib/tree/master/re TODO: 1) fullmatch, finditer, subn, escape, search 2) Match as a type 3) Support flags as constants

Index

Constants

View Source
const ModuleName = "re"

ModuleName defines the expected name for this Module when used in Starlark's load() function, eg: load('re', 'match')

Variables

This section is empty.

Functions

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule loads the re module. It is concurrency-safe and idempotent.

Types

type Regex

type Regex struct {
	// contains filtered or unexported fields
}

Regex is a starlark representation of a compiled regular expression

func (*Regex) Attr

func (r *Regex) Attr(name string) (starlark.Value, error)

Attr gets a value for a string attribute, implementing dot expression support in starklark. required by starlark.HasAttrs interface

func (*Regex) AttrNames

func (r *Regex) AttrNames() []string

AttrNames lists available dot expression strings for time. required by starlark.HasAttrs interface

func (*Regex) Freeze

func (r *Regex) Freeze()

Freeze renders time immutable. required by starlark.Value interface. The interface regex presents to the starlark runtime renders it immutable, making this a no-op

func (*Regex) Hash

func (r *Regex) Hash() (uint32, error)

Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y) required by starlark.Value interface

func (*Regex) String

func (r *Regex) String() string

String implements the Stringer interface

func (*Regex) Truth

func (r *Regex) Truth() starlark.Bool

Truth returns the truth value of an object required by starlark.Value interface. Any non-empty regexp is considered truthy

func (*Regex) Type

func (r *Regex) Type() string

Type returns a short string describing the value's type.

Jump to

Keyboard shortcuts

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