JavaScript Resources
 
 
Categories
Misc

beginners php
programmershelp
programmingsite
software directory
Low Cost domains
Mobile phone business
Free stuff


 

Stores

 

 
Regular Expressions

JavaScript 1.2 supports regular expressions , if you have programmed in PERL you are in luck they both use the same syntax . A regular expression is specified as a sequence of characters within forward slashes / . They can also be a JavaScript string passed to the RegExp( ). There are 2 optional modifiers that you can use and these are g ( for global search ) and i ( which stands for case insensitive search ) . These modifiers follow the second / or are passed to the RegExp( ).

Character what it means
\n , \r , \t matches newline , carriage return and tab
\\ , \ / , \* , \+ , |? , etc etc etc matches a special character , ignores its special meaning
[ . . . . . . ] matches anyone of the characters between the brackets
[^ . . . . . ] matches any character not between the brackets
. match any character other than a new line
\w , \W match any word / non word character
\s , \S match any whitespace / non whitespace
\d , \D match any digit / non digit
^ , $ require match at beginning / end of string or if in multiline ode beginning / end of a line
\b , \B require match at a word boundary / non boundary
? optional term , match 0 or 1 times
+ match previous term one or more times
* match term zero or more times
{n} match previous term exactly n times
{n,} match previous term n or more times
{n,m} match at least n times but no more then m times
a | b match either a or b
(sub) group sub expression sub into a single term and remember text that it matched
n match exactly the same characters that were matched by subexpression number n
$n in replacement strings , substitute the text that matched the nth expression

 

 

© 2003 onwards programmershelp