blob: 2aebf1da22ba819312333742de1495121b417f2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
---
title: match
slug: Web/EXSLT/regexp/match
translation_of: Web/EXSLT/regexp/match
---
<p>{{ XsltRef() }} {{ Fx_minversion_header(3) }}</p>
<p><br>
<code>regexp:match()</code> performs regular expression matching on a string, returning the submatches found as a result.</p>
<h3 id="Syntax" name="Syntax">语法</h3>
<pre class="eval">regexp:match(<em>targetString</em>,<em>regExpString</em>[[,<em>flagsString</em>]])
</pre>
<h3 id="Arguments" name="Arguments">参数</h3>
<dl>
<dt><code><em>targetString</em></code></dt>
<dd>The string to perform regular expression matching upon.</dd>
<dt><code><em>regExpString</em></code></dt>
<dd>The JavaScript style regular expression to evaluate.</dd>
<dt><code><em>flagsString</em></code></dt>
<dd>An optional string containing character flags.</dd>
</dl>
<p>The character flags are:</p>
<dl>
<dt><code>g</code></dt>
<dd>全局匹配</dd>
<dd>The submatches from every match in the string are returned. If this flag isn't specified, only the submatches from the first match are returned.</dd>
<dt><code>i</code></dt>
<dd>Case insensitive match</dd>
<dd>If this flag is specified, the match is performed in a case insensitive fashion.</dd>
</dl>
<h3 id="Returns" name="Returns">Returns</h3>
<p>A node set of <code>match</code> elements, each of which has the string value equal to a portion of the first parameter string as captured by the regular expression. If the match isn't a global one, the first match element has the value of the portion of the string matched by the entire regular expression.</p>
<p>例如:</p>
<pre class="eval"><xsl:for-each select="regExp:match('<span class="nowiki">http://developer.mozilla.org/en/docs/Firefox_3_for_developers</span>',
'(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)')">
Part <xsl:value-of select="position()" /> = <xsl:value-of select="." />
</xsl:for-each>
</pre>
<p>This code generates the following output:</p>
<pre class="eval">Part 1 = <span class="nowiki">http://developer.mozilla.org/en/docs/Firefox_3_for_developers</span>
Part 2 = http
Part 3 = developer.mozilla.org
Part 4 =
Part 5 = /en/docs/Firefox_3_for_developers
</pre>
<h3 id="Defined" name="Defined">定义</h3>
<p><a class="external" href="http://www.exslt.org/regexp/functions/match/index.html">EXSLT - REGEXP:MATCH</a></p>
<h3 id="Gecko_support" name="Gecko_support">Gecko support</h3>
<p>Supported in Gecko 1.9 and later.</p>
<div class="noinclude"> </div>
<p>{{ languages( { "es": "es/EXSLT/regexp/match", "fr": "fr/EXSLT/regexp/match" } ) }}</p>
|