Simple Regular Expressions in Javascript

Need to remove everything except alphabetic/letters in javascript?

Here is a simple example of using javascript to replace/remove characters

Step 1: Create a sample string

var a = “This is a test of the JavaScript RegExp objectZ”

Step 2: Use a regular expression to remove characters that don’t match the characters you want

a.replace(/[^a-zA-Z]/g, ”)
ThisisatestoftheJavaScriptRegExpobjectZ

For more hints and examples in using Regular Expressions

Visit JavaScript RegExp Example- Online Regular Expression Tester

Pretty powerful and awesome one you learn how.

Leave a Reply

Your email address will not be published. Required fields are marked *