Skip to content

Commit

Permalink
Escape strings for use in regex search. (mrdoob#23729)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored and abernier committed Sep 16, 2022
1 parent 3fcf60f commit 753226b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ <h1><a href="https://threejs.org">three.js</a></h1>

}

function escapeRegExp( string ) {

return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847

}

function updateFilter() {

let v = filterInput.value.trim();
Expand All @@ -367,7 +373,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>

//

const regExp = new RegExp( filterInput.value, 'gi' );
const regExp = new RegExp( escapeRegExp( v ), 'gi' );

for ( let pageName in pageProperties ) {

Expand Down
8 changes: 7 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ <h1><a href="https://threejs.org">three.js</a></h1>

}

function escapeRegExp( string ) {

return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847

}

function updateFilter( files, tags ) {

let v = filterInput.value.trim();
Expand All @@ -264,7 +270,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>

}

const exp = new RegExp( v, 'gi' );
const exp = new RegExp( escapeRegExp( v ), 'gi' );

for ( const key in files ) {

Expand Down

0 comments on commit 753226b

Please sign in to comment.