Note that
<script src=”../../node_modules/apg-js/dist/apg-exp-bundle.js”></script>;
defines variables:
apgExp - the apg-exp constructor
and
apgLib - the APG library
const executeApgExp = function () {
let output;
const exp = new apgExp($('#apgexp-def').val());
exp.exclude(['local-char', 'sub-domain-char', 'top-domain-char', 'alpha', 'num', 'special']);
const result = exp.exec($('#email-address').val());
if (result) {
output = result.toHtml();
} else {
output = '<pre>\n';
output += 'result: null';
output += '</pre>\n';
}
$('#apgexp-result').html(output);
};
const regToHtml = function (result) {
let html = '';
const caption = 'result:';
html += `<table class="${apgLib.style.CLASS_STATE}">\n`;
html += `<caption>${caption}</caption>\n`;
html += '<tr>';
html += '<td>input</td>';
html += `<td>${result.input}</td>`;
html += '</tr>\n';
html += '<tr>';
html += '<td>index</td>';
html += `<td>${result.index}</td>`;
html += '</tr>\n';
for (let i = 0; i < result.length; i += 1) {
html += '<tr>';
html += `<td>[${i}]</td>`;
html += `<td>${result[i]}</td>`;
html += '</tr>\n';
}
html += '</table>\n';
return html;
};
const executeRegExp = function () {
let output;
const exp = new RegExp($('#regexp-def').val(), 'i');
const result = exp.exec($('#email-address').val());
if (result) {
output = regToHtml(result);
} else {
output = '<pre>\n';
output += 'result: null';
output += '</pre>\n';
}
$('#regexp-result').html(output);
};
const execute = function () {
executeApgExp();
executeRegExp();
};
$(document).ready(() => {
const string = {};