Methods: toText(), toHtml() and toHtmlPage()
Syntax
var exp = new apgExp(pattern[, flags]); var result = exp.exec(input); var text = exp.toText(); var html = exp.toHtml(); var page = exp.toHtmlPage();
These functions format the last match properties of the exp object for display.
Example 1
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.toText()); /* result */ last match: lastIndex: 0 flags: "" global: false sticky: false unicode: false debug: false input: ---ab12... leftContext: --- lastMatch: ab12 rightContext: ... rules: word : ab12 : alpha : b : num : 2 alias: ["$_"]: ---ab12... ["$`"]: --- ["$&"]: ab12 ["$'"]: ... ["${word}"]: ab12 ["${alpha}"]: b ["${num}"]: 2
Example 2
Same as Example 1, except format the object for HTML page display. exp.toHtmlPage() displays the same HTML but wraps it in a complete page header and body. Include the apg-lib style sheet.<link rel="stylesheet" href="./apg-js/dist/apg-lib-bundle.css" type="text/css" />
/* same as Example 1 */ $("#this-page").html(exp.toHtml()); /* result */
item | value |
---|---|
lastIndex | 0 |
flags | "" |
global | false |
sticky | false |
unicode | false |
debug | false |
item | phrase |
input | ---ab12... |
leftContext | --- |
lastMatch | ab12 |
rightContext | ... |
rule | phrase |
word | ab12 |
alpha | b |
num | 2 |
alias | phrase |
["$_"] | ---ab12... |
["$`"] | --- |
["$&"] | ab12 |
["$'"] | ... |
["${word}"] | ab12 |
["${alpha}"] | b |
["${num}"] | 2 |