XU XUv0.8.8
EN

API

#regexp

import: #regexp

counts: 2 函数, 14 方法, 4 类型, 0 常量, 0 方法集

正则子集:compile/match/find/replace;有界回溯。

struct Regexp

XuAPI
pub struct Regexp {
    pub nodes []Node
    pub root int
    pub class_data string
    pub steps_max int
    pub num_caps int
}

用途

公开结构体 `Regexp`。

参数

nodes []Node
字段([]Node)
root int
字段(int)
class_data string
字段(string)
steps_max int
字段(int)
num_caps int
字段(int)

quote_meta

XuAPI
pub fn quote_meta(s &string) string

用途

加引号meta。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

compile

XuAPI
pub fn compile(expr string) Regexp

用途

compile,返回 Regexp。失败时 throw。

参数

expr string
expr(string)

返回

Regexp — 该类型的值

(Regexp) num_subexp

XuAPI
pub fn (re Regexp) num_subexp() int

用途

`Regexp` 上的方法:分子subexp。

参数

re Regexp
接收者 Regexp(值接收者)

返回

int — 该类型的值

(Regexp) find_submatch

XuAPI
pub fn (re Regexp) find_submatch(s &string) []string

用途

`Regexp` 上的方法:findsubmatch。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

[]string — 切片结果

struct Submatch

XuAPI
pub struct Submatch {
    pub start int
    pub end int
    pub parts []string
}

用途

公开结构体 `Submatch`。

参数

start int
字段(int)
end int
字段(int)
parts []string
各段

(Regexp) find_all_submatch

XuAPI
pub fn (re Regexp) find_all_submatch(s &string, n int) [][]string

用途

`Regexp` 上的方法:findallsubmatch。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
n int
数量、长度或上限(int)

返回

[][]string — 切片结果

(Regexp) expand

XuAPI
pub fn (re Regexp) expand(s &string, repl &string) string

用途

在 `Regexp` 上调用 `expand`。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
repl &string
repl(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

struct LiteralPrefix

XuAPI
pub struct LiteralPrefix {
    pub prefix string
    pub complete bool
}

用途

公开结构体 `LiteralPrefix`。

参数

prefix string
前缀
complete bool
字段(bool)

(Regexp) literal_prefix

XuAPI
pub fn (re Regexp) literal_prefix() LiteralPrefix

用途

`Regexp` 上的方法:literalprefix。

参数

re Regexp
接收者 Regexp(值接收者)

返回

LiteralPrefix — 该类型的值

(Regexp) match_string

XuAPI
pub fn (re Regexp) match_string(s &string) bool

用途

`Regexp` 上的方法:match字符串。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

bool — 是否成立

(Regexp) find

XuAPI
pub fn (re Regexp) find(s &string) string

用途

在 `Regexp` 上调用 `find`。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

struct Index

XuAPI
pub struct Index {
    pub start int
    pub end int
}

用途

公开结构体 `Index`。

参数

start int
字段(int)
end int
字段(int)

(Regexp) find_index

XuAPI
pub fn (re Regexp) find_index(s &string) Index

用途

`Regexp` 上的方法:find下标。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

Index — 该类型的值

(Regexp) find_all_index

XuAPI
pub fn (re Regexp) find_all_index(s &string, n int) []Index

用途

`Regexp` 上的方法:findall下标。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
n int
数量、长度或上限(int)

返回

[]Index — 切片结果

(Regexp) find_all

XuAPI
pub fn (re Regexp) find_all(s &string, n int) []string

用途

`Regexp` 上的方法:findall。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
n int
数量、长度或上限(int)

返回

[]string — 切片结果

(Regexp) split

XuAPI
pub fn (re Regexp) split(s &string, n int) []string

用途

`Regexp` 上的方法:按分隔符切开。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
n int
数量、长度或上限(int)

返回

[]string — 切片结果

(Regexp) find_submatch_index

XuAPI
pub fn (re Regexp) find_submatch_index(s &string) []Index

用途

`Regexp` 上的方法:findsubmatch下标。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

[]Index — 切片结果

(Regexp) replace_all_literal

XuAPI
pub fn (re Regexp) replace_all_literal(s &string, repl &string) string

用途

`Regexp` 上的方法:替换allliteral。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
repl &string
repl(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

(Regexp) replace_all

XuAPI
pub fn (re Regexp) replace_all(s &string, repl &string) string

用途

`Regexp` 上的方法:替换全部出现的子串。

参数

re Regexp
接收者 Regexp(值接收者)
s &string
源字符串(借用,调用方仍持有;类型 &string)
repl &string
repl(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串