Common RegExp in JavaScript

Share:
A regular expression is an object that describes a pattern of characters. Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

Common RegEx:
JavaScript
Numeric /^[0-9]+$/
Alphabets /^[a-zA-Z]+$/
Alphanumeric /^[0-9a-zA-Z]+$/
Email /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/



Expression Description
[abc] Find any character between the brackets
[^abc] Find any character NOT between the brackets
[0-9] Find any character between the brackets (any digit)
[^0-9] Find any character NOT between the brackets (any non-digit)
(x|y) Find any of the alternatives specified

Methods:
Method Description
exec() Tests for a match in a string. Returns the first match
test( Tests for a match in a string. Returns true or false
toString() Returns the string value of the regular expression

For tutorial you can visit: w3schools

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments