if you are free today, you can write a calendar. on the Internet, you can see the Code formatted with a javascript date, A little dizzy after reading it. Code:
/** <Br/> * @ Param d the delimiter <br/> * @ Param p the pattern of your date <br/> * @ author meizz <br/> *@ author kimsoft add W + pattern <br/> */<br/> date. prototype. format = function (style) {<br/> var o = {<br/> "m +": This. getmonth () + 1, // month <br/> "d +": This. getdate (), // day <br/> "H +": This. gethours (), // hour <br/> "m +": This. getminutes (), // minute <br/> "s +": This. getseconds (), // second <B R/> "W +": "/u65e5/u4e00/u4e8c/u4e09/u56db/u4e94/u516d ". charat (this. getday (), // week <br/> "q +": math. floor (this. getmonth () + 3)/3), // quarter <br/> "S": This. getmilliseconds () // millisecond <br/>}< br/> If (/(Y + )/. test (style) {<br/> style = style. replace (Regexp. $1, (this. getfullyear () + ""). substr (4-Regexp. $1. length); <br/>}< br/> for (var k in O) {<br/> If (New Regexp ("(" + K + ") "). test (Style) {<Br/> style = style. Replace (Regexp. $1, Regexp. $1. Length = 1? O [k]: ("00" + O [k]). substr ("" + O [k]). length); <br/>}< br/> return style; <br/> };
The above code shows Regexp. $1. I checked it to find out:
$1... $9 is an attribute of Regexp, $1... $9: indicates the matching result of group N, which is useful when multiple groups in the regular expression are grouped.
In JScript, A String object related to a regular expression is called replace. But how to use a regular expression to match the result in replace?
In this case, we need to use the "matching variable". The matching variable is used to represent the result of regular expression matching. The following describes the matching variables:
$ & -- Indicates the matching results of all matching groups. The matching group is the () Group of the regular expression.
$ -- Represents $ characters. Because $ characters are used for matching variables, escape
$ N -- similar to the previous $1... $9 indicates the result of group N matching
$ NN -- the result of the NN group match is very simple.
$ '-- The leftcontext mentioned above. For example, if abcdefg is matched with D, ABC is its leftcontext.
$ '-- It is very close to the above and should not be mistaken !, This is rightcontext.