Properties and methods of regular expression objects
Predefined regular expressions have the following static properties: INPUT, MULTILINE, Lastmatch, Lastparen,
LeftContext, RightContext and $ 1 to $ 9. The Input and Multiline can be pre-set. The value of other properties is
Different values are assigned to different conditions after executing the EXEC or TEST method. Many properties have long and short (Perl
Two names of the style, and, these two names point to the same value. (JavaScript simulation perl regular expression)
Regular expression object Properties Property Meaning $ 1 ... $ 9 If it (,) exists, it is a substring $ _ see INPUT $ *
See Multiline $ & See LastParen $ `See LEFTCONTEXT $ '
See Rightcontext Constructionor
Create a special function prototype GLOBAL for an object
Do you match (BOOL type) Ignorecase throughout the string
Does it ignore the case (BOOL) INPUT when matching
Mapped string LastIndex
Last one match index lastparen
The last brackets enclosed in the brackets LeftContext
The last time you match the left sub-string Multiline
Do you have multi-line match (BOOL type) prototype
Allow additional properties to the object RightContext
Sub string Source, which matches the right time
Regular expression mode LastIndex
The last match index
Method of regular expression object
Method Meaning Compile
Regular expression compare EXEC
Execute Test
Match TOSource
Returns a definition of a particular object (LITERAL REPRESENG) whose value can be used to create a new object. Overload
Object.tosource method is obtained. Tostring
Returns the string of a particular object. The Object.toString method is overloaded. Valueof
Returns the original value of a particular object. Receive an example of Object.Valueof method
Var myReg = / (w ) s (w ) /;
Var str = "john smith";
Var newstr = str.replace (MyReg, "$ 2, $ 1");
Document.write (newstr);
script>
"Smith, John" will be output