Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[·­Òë]High Performance JavaScript(017)

A Note on Benchmarking  ²âÊÔ»ù׼˵Ã÷
    Because a regex's performance can be wildly different depending on the text it's applied to, there's no straightforward way to benchmark regexes against each other. For the best result, you need to benchmark your regexes on test strings of varying lengths that match, don't match, and nearly match.
    ÒòΪÕýÔò±í´ïʽÐÔÄÜÒòÓ¦ÓÃÎı¾²»Í¬¶ø²úÉúºÜ´ó²îÒ죬ûÓмòµ¥Ã÷Á˵ķ½·¨¿ÉÒÔ²âÊÔÕýÔò±í´ïʽ֮¼äµÄÐÔÄܲî±ð¡£ÎªµÃµ½×îºÃµÄ½á¹û£¬ÄãÐèÒªÔÚ¸÷ÖÖ×Ö·û´®ÉϲâÊÔÄãµÄÕýÔò±í´ïʽ£¬°üÀ¨²»Í¬³¤¶È£¬Äܹ»Æ¥ÅäµÄ£¬²»ÄÜÆ¥ÅäµÄ£¬ºÍ½üËÆÆ¥ÅäµÄ¡£
    That's one reason for this chapter's lengthy backtracking coverage. Without a firm understanding of backtracking, you won't be able to anticipate and identify backtracking-related problems. To help you catch runaway backtracking early, always test your regexes with long strings that contain partial matches. Think about the kinds of strings that your regexes will nearly but not quite match, and include those in your tests.
    ÕâÒ²ÊDZ¾Õ³¤Æª´óÂÛ»ØËݵÄÔ­ÒòÖ®Ò»¡£Èç¹ûûÓÐÈ·ÇÐÀí½â»ØËÝ£¬¾ÍÎÞ·¨Ô¤²âºÍÈ·¶¨»ØËÝÏà¹ØÎÊÌ⡣Ϊ°ïÖúÄãÔçÈÕ°ÑÎÕ»ØËÝʧ¿Ø£¬×ÜÊÇÓðüº¬ÌØÊâÆ¥ÅäµÄ³¤×Ö·û´®²âÊÔÄãµÄÕýÔò±í´ïʽ¡£Õë¶ÔÄãµÄÕýÔò±í´ïʽ¹¹Ë¼Ò»Ð©½üËÆµ«²»ÄÜÍêȫƥÅäµÄ×Ö·û´®£¬½«ËûÃÇÓ¦ÓÃÔÚÄãµÄ²âÊÔÖС£
More Ways to Improve Regular Expression Efficiency  Ìá¸ßÕýÔò±í´ïʽЧÂʵĸü¶à·½·¨
    The following are a variety of additional regex efficiency techniques. Several of the points here have already been touched upon during the backtracking discussion.
    ÏÂÃæÊÇһдÌá¸ßÕýÔò±í´ïʽЧÂʵļ¼Êõ¡£¼¸¸ö¼¼ÊõµãÒѾ­ÔÚ»ØËݲ¿·ÖÌÖÂÛ¹ýÁË¡£
Focus on failing faster
¹Ø×¢ÈçºÎÈÃÆ¥Åä¸ü¿ìʧ°Ü
    Slow regex processing is usually caused by slow failure rather than slow matching. This is compounded by the fact that if you're using a regex to match small parts of a large string, the regex will fail at many more positions than it will succeed. A change that makes a r


Ïà¹ØÎĵµ£º

ͨ¹ýjavascript»ñµÃurl²ÎÊý

Ò³ÃæÌá½»Êý¾ÝÒ»°ãÓÐÁ½ÖÖ·½·¨£ºget,post¡£post¾ÍÊÇËùνµÄformÌá½»£¬Ê¹ÓÃÊÓͼ£»getÊÇͨ¹ýurlÌá½»¡£
Get·½·¨Ò»°ãÓúǫ́´úÂ루Èçasp,asp.net£©»ñµÃ²ÎÊý£¬´úÂëºÜ¼òµ¥£ºRequest.QueryString["id"];¼´¿É»ñÈ¡¡£ 
ÓÐЩʱºòÐèÒªÖ±½ÓÔÚǰ̨»ñÈ¡url²ÎÊý£¬ÒªÓõ½javascript£¬jsûÓÐÖ±½Ó»ñÈ¡url²ÎÊýµÄ·½·¨£¬ÄÇô£¬ÎÒÃÇÈçºÎͨ¹ýjs ......

JavaScript»ù´¡ÖªÊ¶1

JavascriptÊý¾ÝÀàÐÍ
ÓÉÓÚjavascriptÊÇÈõÀàÐÍÓïÑÔ£¬¼´¶¨Òå±äÁ¿Ê±²»±ØÉùÃ÷ÆäÀàÐÍ
¡£µ«Õâ²¢²»Òâζ×űäÁ¿Ã»ÓÐÀàÐÍ¡£ÒòΪ¸³ÖµÊ±»á×Ô¶¯Æ¥ÅäÊý¾ÝÀàÐÍ£¡
ĿǰÓõ½µÄ»ù±¾Êý¾ÝÀàÐÍ
number
boolean
string
var i
i="test";//Õâʱi¾Í³ÉÁËstringÀàÐÍ
var i
i=4;//Õâʱi¾Í³ÉÁËnumberÀàÐÍ
³£ÓöÔÏóÀàÐÍ<object> ......

javaScript¹Ø±Õä¯ÀÀÆ÷ (²»µ¯³öÌáʾ¿ò)

£¼script language="javaScript"£¾
function closeWindow()
{
¡¡window.opener = null;
¡¡window.open(' ', '_self', ' ');
¡¡window.close();
}
£¼/script£¾
£¼input type='button' value='¹Ø±Õ´°¿Ú' onClick="closeWindow()"£¾
»ò
£¼input type="button" value="¹ ......

JavaScript»ù´¡ÖªÊ¶2

ÍæPHP¡¢Delphi¡¢Java»ù±¾É϶¼ÓжÔÏó£¬Ï°¹ßÕâÖÖ˼·ºóÉÏÊÖÈκÎÓïÑÔ¶¼Ïë¿¿OO˼·£¬Õâ¾ø²»ÊÇÔÚ¸Ïʱ÷Ö£¬¶øÊǰÑÏà¹Ø´úÂë½øÐÐÄÚ¾ÛµÄÈ·¿ÉÒÔÌå»áµ½Î¬»¤µÄ·½±ã£¡
ÔÚJavaScriptÖÐÈçºÎ´´½¨¶ÔÏó£¿
JavaScriptÊÇ»ùÓÚ¶ÔÏóµÄ£¡ËüÒ²ÊÇÒÔObjectΪ¸ùÀ࣬ÆäËüÀà¼Ì³ÐÖ®¡£ÔÚ¸ùÀàÌṩÁ˼¸¸ö·½·¨¡£¹©¼Ì³ÐÀàʹÓã¡
ÒÔÏÂÊÇ´´½¨¶ÔÏóµÄÀý×Ó£º
funct ......

Javascript¼ì²éÈÕÆÚ¸ñʽÊÇ·ñºÏ·¨µÄÒ»ÖÖ¼ò»¯·½·¨¡£

³£¹æµÄ·½·¨Êǽ«ÄêÔÂÈÕÈ¡³ö£¬È»ºó·Ö±ðÅжϷ¶Î§£¬È»ºó¾ÍÅжÏÈòÄê2ÔµÄÌìÊý
¿ÉÒÔͨ¹ýnew Date(string)µÄ¹¹Ô죬±È½ÏÄêÔÂÈÕ×Ö·ûÊÇ·ñ·¢Éú±ä»¯Åжϡ£
function CheckDate(text) {
if (!text) return false;
text = text.replace(/[\/-]0?/g, "/");
if (!text.match(/^\d{4}\/\d{1,2}\/\d{1,2}$/)) return true; ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ