Skip to content

Commit

Permalink
Demo: regexize pattern str
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Oct 25, 2024
1 parent 8a4d7a8 commit 8e5c21c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function showOutput(el) {
optimize: optionOptimizeValue,
target: optionTargetValue,
});
output = `/${re.pattern ? re.pattern : '(?:)'}/${re.flags}`;
output = `/${regexize(re.pattern)}/${re.flags}`;
} catch (e) {
outputEl.classList.add('error');
output = `Error: ${e.message}`;
Expand All @@ -47,6 +47,10 @@ function escapeHtml(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;');
}

function regexize(str) {
return str === '' ? '(?:)' : str.replace(/\\?./gsu, m => m === '/' ? '\\/' : m);
}

function setFlagI(checked) {
useFlagI = checked;
showOutput(inputEl);
Expand Down

0 comments on commit 8e5c21c

Please sign in to comment.