11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 8-7: Static Properties of the RegExp Class Object<br />

Property Alternat<br />

e Form<br />

Value Example<br />

may be better<br />

to use the<br />

length of the<br />

regexp<br />

pattern and<br />

the lastIndex<br />

property to<br />

calculate<br />

this value.<br />

>input >$_ >String<br />

containing the<br />

default string<br />

to match<br />

against the<br />

pattern.<br />

>lastIndex >None >Integer<br />

specifying the<br />

position in the<br />

string at which<br />

to start the<br />

next match.<br />

Same as the<br />

instance<br />

property,<br />

which should<br />

be used<br />

instead.<br />

>lastMatch >$&<br />

>String<br />

containing<br />

the most<br />

recently<br />

matched text.<br />

>lastParen >$+ >String<br />

containing<br />

the text of the<br />

last<br />

parenthesized<br />

subexpressio<br />

n of the most<br />

recent match.<br />

>leftContext >$` >String<br />

containing the<br />

text to the left<br />

>var pattern = /(cat) (dog)/g;<br />

pattern.test("this is a<br />

cat dog and cat dog");<br />

document.writeln RegExp.input);<br />

// prints "this is a cat dog and<br />

cat dog"<br />

document.writeln(RegExp['$_ ']);<br />

>var pattern = /(cat) (dog)/g;<br />

pattern.test("this is a<br />

cat dog and cat dog");<br />

document.writeln(RegExp.lastIndex);<br />

// prints 17<br />

>var pattern = /(cat) (dog)/g;<br />

pattern.test("this is a<br />

cat dog and cat dog");<br />

document.writeln<br />

(RegExp.lastMatch);<br />

// prints "cat dog"<br />

document.writeln<br />

(RegExp['$&']);<br />

// prints "cat dog"<br />

>var pattern = /(cat) (dog)/g;<br />

pattern.test("this is a<br />

cat dog and cat dog");<br />

document.writeln<br />

(RegExp.lastParen);<br />

// prints dog<br />

document.writeln(RegExp['$+ ']);<br />

// prints "dog"<br />

>var pattern = /(cat) (dog)/g;<br />

pattern.test("this is a<br />

cat dog and cat dog");

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!