{"id":1490,"date":"2014-11-14T14:57:24","date_gmt":"2014-11-14T14:57:24","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=1490"},"modified":"2018-03-01T13:50:11","modified_gmt":"2018-03-01T05:50:11","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e4%b8%ad%e7%9a%84%e4%b8%80%e4%ba%9btips%e6%85%a2%e6%85%a2%e7%a7%af%e7%b4%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/1490.html","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u4e00\u4e9btips[\u6162\u6162\u79ef\u7d2f]"},"content":{"rendered":"<h5><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u4e00\u4e9b\u5751<\/strong><\/h5>\n<h6><strong>0.\u5b57\u7b26\u7ec4<\/strong><\/h6>\n<p>\u5728Python\u4e2d\u4f7f\u7528\u7684\u662f\u4e2d\u62ec\u53f7\u201c[]\u201d\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u7ec4\u6210\u9700\u8981\u662f\u5355\u4e2a\u7684\u201c\u5b57\u7b26\u201d\uff0c\u5c31\u7b97\u662f\u7528\u201c()\u201d\u62ec\u8d77\u6765\u7684\uff0c\u4e5f\u65e0\u6cd5\u8868\u793a\u5355\u4e2a\u7684\u5b57\u7b26\uff0c\u5f88\u5bb9\u6613\u51fa\u9519\uff01<\/p>\n<p>\u6d4b\u8bd5\u6570\u636e\uff1a<\/p>\n<pre class=\"lang:default decode:true\">\"nt\":\"3gnet\"\r\n\"nt\":\"2g\/3g\"\r\n\"nt\":\"cmnet\"\r\n\"nt\":\"cmwap\"\r\n\"nt\":\"ctnet\"\r\n\"nt\":\"ctwap\"<\/pre>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n<pre class=\"lang:default decode:true\">regex_net = re.compile(r'(3gnet)|(2g\/3g)|(c(m|t)(net|wap))', re.I)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u6b63\u786e\uff01\r\nregex_net = re.compile(r'(3gnet)|(2g\/3g)|(c[mt]((net)|(wap)))', re.I)\u00a0\u00a0 #\u6b63\u786e\uff01\r\n#regex_net = re.compile(r'(3gnet)|(2g\/3g)|(c[mt][net|wap])', re.I)\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u9519\u8bef\uff01\r\n#regex_net = re.compile(r'(3gnet)|(2g\/3g)|(c[mt][(net)|(wap)])', re.I) #\u9519\u8bef\uff01\r\n#regex_net = re.compile(r'(3gnet)|(2g\/3g)|(cmnet)|(cmwap)|(ctnet)', re.I)\u00a0 #\u592a\u4e11\u964b\u2026\u2026<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/9801630\/what-is-the-difference-between-square-brackets-and-parentheses-in-a-regex\" target=\"_blank\" rel=\"noopener\">What is the difference between square brackets and parentheses in a regex? &#8211; Stack Overflow<\/a><\/li>\n<li><a href=\"http:\/\/www.regular-expressions.info\/brackets.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.regular-expressions.info\/brackets.html<\/a><\/li>\n<li><a href=\"http:\/\/www.regular-expressions.info\/posixbrackets.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.regular-expressions.info\/posixbrackets.html<\/a><\/li>\n<li><a href=\"http:\/\/zhidao.baidu.com\/link?url=fjSrIVhkwLVAdmNHd6aae-TPtX2MYYRleOt2bdHmF4W4XJ1_CHLnH9Ye6NRmXAiKCulwUJYMx2XYb6kTjIE7y-YzQkSLTgqw-WHjns69aL_\" target=\"_blank\" rel=\"noopener\">\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u5c0f\u62ec\u53f7\u548c\u4e2d\u62ec\u53f7\uff0c\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f_\u767e\u5ea6\u77e5\u9053<\/a><\/li>\n<\/ul>\n<h6>1.\u4f7f\u7528\u975e\u8d2a\u5a6a\u5339\u914d\u8868\u8fbe\u5f0f\u65f6\u8981\u975e\u5e38\u6ce8\u610f\u7684\u70b9\uff01<\/h6>\n<pre class=\"lang:default decode:true\">sqli_regex1 = re.compile(r'(select|insert|update|delete).+?(where|values|set)(.+?) &lt;\/', re.I|re.S)\r\nsqli_regex2 = re.compile(r'(select|insert|update|delete).+?(where|values|set)(.+?)', re.I|re.S)\r\nsqli_regex3 = re.compile(r'(select|insert|update|delete).+?(where|values|set)(.+?)$', re.I|re.S)<\/pre>\n<p>\u7b2c\u4e00\u79cdsqli_regex1\u662f\u51c6\u786e\u6307\u5b9a\uff0c\u6ca1\u6709\u95ee\u9898\uff1b<br \/>\n\u7b2c\u4e8c\u79cdsqli_regex2\u5c31\u5b58\u5728\u95ee\u9898\u4e86\uff0c\u6b64\u5904\u7684\u975e\u8d2a\u5a6a\u5339\u914d\u53ea\u80fd\u5339\u914d\u4e00\u4e2a\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u5339\u914d\u81f3\u884c\u5c3e\uff08\u5982\u679c\u8981\u4fee\u6539\u7684\u8bdd\uff0c\u53ef\u4ee5\u5c06\u201c(.+?)\u201d\u4fee\u6539\u4e3a\u201c(.*?)\u201d\u5373\u53ef\uff09\uff1b<br \/>\n\u7b2c\u4e09\u79cdsqli_regex3\u4e5f\u6ca1\u95ee\u9898\uff0c\u56e0\u4e3a\u624b\u52a8\u6307\u5b9a\u4e86\u201c$\u201d\u884c\u5c3e\u6807\u8bc6\u3002<\/p>\n<h6>2.\u4e00\u4e9b\u9009\u9879\uff08\u591a\u884c\u5339\u914d\u3001\u5ffd\u7565\u5927\u5c0f\u5199\u2026\u2026\uff09<\/h6>\n<pre class=\"lang:default decode:true\">re.I\r\nre.IGNORECASE\r\nPerform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.\r\n\r\nre.L\r\nre.LOCALE\r\nMake w, W, b, B, s and S dependent on the current locale.\r\n\r\nre.M\r\nre.MULTILINE\r\nWhen specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline); and the pattern character '$' matches at the end of the string and at the end of each line (immediately preceding each newline). By default, '^' matches only at the beginning of the string, and '$' only at the end of the string and immediately before the newline (if any) at the end of the string.\r\n\r\nre.S\r\nre.DOTALL\r\nMake the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline.\uff08 re.S \u5373\u4e3a '.' \u5e76\u4e14\u5305\u62ec\u6362\u884c\u7b26\u5728\u5185\u7684\u4efb\u610f\u5b57\u7b26 \uff09\r\n\r\nre.U\r\nre.UNICODE\r\nMake w, W, b, B, d, D, s and S dependent on the Unicode character properties database.\uff08New in version 2.0.\uff09<\/pre>\n<h6>3.\u5c06\u591a\u884c\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5355\u884c\u5b57\u7b26\u4e32\uff08\u53bb\u6389\u884c\u5185\u8fde\u7eed\u7684\u591a\u4e2a\u7a7a\u767d\u5b57\u7b26\u2014\u2014\u6362\u884c\u7b26\u3001\u7a7a\u683c\u3001Tab\u7b26\u53f7\uff09<\/h6>\n<p>x = string.join(multi_line_str.split(), &#8216; &#8216;)<br \/>\n\u5373\uff0c\u5148str.split\uff0c\u7136\u540e\u518dstring.join()\uff08\u6ce8\u610f\u7b2c\u4e8c\u4e2a\u662fstring.join()\u800c\u4e0d\u662fstr.join()\uff09<br \/>\n<a href=\"https:\/\/docs.python.org\/2\/library\/stdtypes.html#str.split\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.python.org\/2\/library\/stdtypes.html#str.split<\/a><br \/>\n<a href=\"https:\/\/docs.python.org\/2\/library\/string.html#string.join\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.python.org\/2\/library\/string.html#string.join<\/a><\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/re.html#re.finditer\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.python.org\/2\/library\/re.html#re.finditer<\/a><\/li>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/re.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.python.org\/2\/library\/re.html<\/a><\/li>\n<li><a href=\"http:\/\/www.cnblogs.com\/huxi\/archive\/2010\/07\/04\/1771073.html\" target=\"_blank\" rel=\"noopener\">Python\u6b63\u5219\u8868\u8fbe\u5f0f\u6307\u5357<\/a><\/li>\n<li><a href=\"http:\/\/www.ibm.com\/developerworks\/cn\/opensource\/os-cn-pythonre\/index.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.ibm.com\/developerworks\/cn\/opensource\/os-cn-pythonre\/index.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u4e00\u4e9b\u5751 0.\u5b57\u7b26\u7ec4 \u5728Python\u4e2d\u4f7f\u7528\u7684\u662f\u4e2d\u62ec\u53f7\u201c[]\u201d\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u7ec4\u6210\u9700\u8981\u662f\u5355\u4e2a\u7684\u201c\u5b57\u7b26\u201d\uff0c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6,7],"tags":[393,1044],"class_list":["post-1490","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-other","category-programing","tag-re","tag-1044"],"views":3147,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=1490"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1490\/revisions"}],"predecessor-version":[{"id":3806,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1490\/revisions\/3806"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=1490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=1490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=1490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}