topical media & game development
mobile-js-parts-ch07.txt / txt
chapter: Regular Expressions
==================
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)
(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?
====================================
var parse_number = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?/i
====================================
-?
====================================
\d+
====================================
(?:\.\d*)?
====================================
(?:e[+\-]?\d+)?
====================================
// Make a regular expression object that matches
// a JavaScript string.
var my_regexp = /"(?:\\.|[^\\\"])*"/g;
====================================
// Make a regular expression object that matches
// a JavaScript string.
var my_regexp = new RegExp("\"(?:\\\\.|[^\\\\\\\"])*\"", 'g');
====================================
function make_a_matcher( ) {
return /a/gi;
}
var x = make_a_matcher( );
var y = make_a_matcher( );
// Beware: x and y are the same object!
x.lastIndex = 10;
document.writeln(y.lastIndex); // 10
====================================
"into".match(/in|int/)
====================================
\ / [ ] ( ) { } ? + * | . ^ % & ' ( ) * +, - . / :
; < = > ? @ [ \ ] ^ _ ` { | } ˜
====================================
(?:!|"|#|$|%|&|'|\(|\)|\*|\+|,|-|\.|\/|:|;|<|=|>|@|\[|\\|]|^|_|` |\{|\||\}|˜)
====================================
[!-\/:-@\[-`{-˜]
====================================
/ [ \ ] ^
==================
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.