-
Notifications
You must be signed in to change notification settings - Fork 1
/
lastMatch.html
92 lines (92 loc) · 3.29 KB
/
lastMatch.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<title>apg-exp</title>
<meta charset="utf-8">
<link rel="stylesheet" href="./css/BrightSide.css" type="text/css" />
<script type="text/javascript" src="./import.js"></script>
</head>
<body>
<div id="wrap">
<div id="header"></div>
<div id="content-wrap">
<img src="./images/PointLobosCropped.jpg" width="820" height="120" alt="headerphoto" class="no-border" />
<div id="sidebar"></div>
<div id="main-2col">
<!-- page content goes here -->
<h1>Last Match Properties</h1>
<p>
After a successful pattern-matching attempt, the ApgExp object retains
information about the last-matched patterns or phrases. Unlike the
<a href="./result.html">result</a> object which retains <i>all</i>
matched phrases for all rule names, the ApgExp object retains only the last matched.
</p>
<h3>Syntax</h3>
<pre>
var exp = new ApgExp(pattern[, flags]);
var result = exe.exec(input);
</pre>
<h3>Last Match Properties</h3>
<ul>
<li><kbd>exe.input</kbd> (alias <kbd>exe["$_"]</kbd>):
A copy of the input string<sup>†</sup>.</li>
<li><kbd>exe.lastMatch</kbd> (alias <kbd>exe["$&"]</kbd>):
A copy of the last-matched pattern - same as <a href="./result.html">result[0]</a></li>
<li><kbd>exe.leftContext</kbd> (alias <kbd>exe["$`"]</kbd>):
Prefix of the input string up to the first character of the matched pattern.</li>
<li><kbd>exe.rightContext</kbd> (alias <kbd>exe["$'"]</kbd>):
Suffix of the input string, the phrase following the matched pattern.</li>
<li><kbd>exe.rules</kbd> (alias <kbd>exe["${rule-name}"]</kbd>):
The last-matched phrase for the named rule.</li>
</ul>
<p><sup>†</sup> If Unicode mode is <kbd>true</kbd>, i.e. <kbd>flags = "u"</kbd>, all strings are arrays
of integer character codes, otherwise it is a JavaScript string.</p>
<h3>See Also</h3>
<ul>
<li><kbd><a href="./toText.html">exe.toText()</a></kbd></li>
<li><kbd><a href="./toText.html">exe.toHtml()</a></kbd></li>
<li><kbd><a href="./toText.html">exe.toHtmlPage()</a></kbd></li>
</ul>
<h3>Example</h3>
<p>
<pre>
var pattern, exp, str, result;
pattern = 'word = alpha *(alpha / num)\n';
pattern += 'alpha = %d65-90 / %d97-122\n';
pattern += 'num = %d48-57\n';
exp = new ApgExp(pattern);
str = "---ab12...";
result = exp.exec(str);
console.log("exp.leftContext : "+exp.leftContext);
console.log('exp["$`"] : '+exp["$`"]);
console.log("exp.lastMatch : "+exp.lastMatch);
console.log('exp["$&"] : '+exp["$&"]);
console.log("exp.rightContext: "+exp.rightContext);
console.log('exp["$\'"] : '+exp["$'"]);
console.log("exp.rules.word : "+exp.rules.word);
console.log("exp[${word}] : "+exp["${word}"]);
console.log("exp.rules.alpha : "+exp.rules.alpha);
console.log("exp[${alpha}] : "+exp["${alpha}"]);
console.log("exp.rules.num : "+exp.rules.num);
console.log("exp[${num}] : "+exp["${num}"]);
/* result */
exp.leftContext : ---
exp["$`"] : ---
exp.lastMatch : ab12
exp["$&"] : ab12
exp.rightContext: ...
exp["$'"] : ...
exp.rules.word : ab12
exp[${word}] : ab12
exp.rules.alpha : b
exp[${alpha}] : b
exp.rules.num : 2
exp[${num}] : 2
</pre>
</p>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>