mozilla

Compare Revisions

Regular Expressions

Change Revisions

Revision 330547:

Revision 330547 by teddybeard on

Revision 331165:

Revision 331165 by rodneyrehm on

Title:
Regular Expressions
Regular Expressions
Slug:
JavaScript/Guide/Regular_Expressions
JavaScript/Guide/Regular_Expressions
Tags:
"Regular Expressions", "NeedsBrowserCompatibility", "JavaScript"
"Regular Expressions", "NeedsBrowserCompatibility", "JavaScript"
Content:

Revision 330547
Revision 331165
tt505    <p>
506      Escaping user input to be treated as a literal string withi
 >n a regular expression can be accomplished by simple replacement:
507    </p>
508    <pre class="brush: js">
509function escapeRegExp(string){
510  return string.replace(/([.*+?^=!:${}()|[\]\/\\])/g, "\\$1");
511}
512</pre>

Back to History