regex() Function (SLAX and XSLT)
命名 空间
http://xml.juniper.net/junos/commit-scripts/1.0 http://xml.libslax.org/slax
SLAX 语法
var $result = prefix:regex(pattern, string);
XSLT 语法
<xsl:variable name="result" select="prefix:regex(pattern, string)"/>
描述
根据给定的字符串参数计算正则表达式并返回任何匹配项。此函数需要两个参数:正则表达式和正则表达式与之比较的字符串。
与命名空间 URI 关联的应在 prefix 样式表的前缀到命名空间映射中定义。
参数
pattern |
根据字符串参数计算的正则表达式。 |
string |
用于在其中搜索指定正则表达式的匹配项的字符串。 |
返回值
result |
与字符串参数中的给定正则表达式模式匹配的字符串数组。 |
使用示例
在以下示例中,正则表达式模式由四个不同的组组成。第一组由整个表达式组成。随后的三个组分别是主表达式中的括号括起来的表达式。每个函数调用的结果都包含一个正则表达式模式与每个 jcs:regex()
指定字符串的匹配项数组。
var $pattern = "([0-9]+)(:*)([a-z]*)"; var $a = jcs:regex($pattern, "123:xyz"); var $b = jcs:regex($pattern, "r2d2"); var $c = jcs:regex($pattern, "test999!!!"); $a[1] == "123:xyz" # string that matches the full reg expression $a[2] == "123" # ([0-9]+) $a[3] == ":" # (:*) $a[4] == "xyz" # ([a-z]*) $b[1] == "2d" # string that matches the full reg expression $b[2] == "2" # ([0-9]+) $b[3] == "" # (:*) [empty match] $b[4] == "d" # ([a-z]*) $c[1] == "999" # string that matches the full reg expression $c[2] == "999" # ([0-9]+) $c[3] == "" # (:*) [empty match] $c[4] == "" # ([a-z]*) [empty match]
发布信息
Junos OS 7.6 版中引入的功能
对 slax 命名空间的支持 http://xml.libslax.org/slax 在 Junos OS 12.2 版中添加。