{"id":264,"date":"2023-10-22T10:13:04","date_gmt":"2023-10-22T02:13:04","guid":{"rendered":"https:\/\/nnn.ink:368\/?p=264"},"modified":"2023-10-22T11:45:42","modified_gmt":"2023-10-22T03:45:42","slug":"%e6%89%b9%e9%87%8f%e9%87%8d%e5%91%bd%e5%90%8d%e5%b7%a5%e5%85%b7-bulk-rename-utility%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.biyuntang.com\/?p=264","title":{"rendered":"\u6279\u91cf\u91cd\u547d\u540d\u5de5\u5177 &#8212; Bulk Rename Utility\u6559\u7a0b"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u3010Bulk Rename Utility \u662f\u6709\u6548\u7684\u3001\u7b80\u6d01\u7684\u6587\u4ef6\u540d\u6279\u91cf\u66ff\u6362\u5de5\u5177\uff0c\u4f46\u5982\u679c\u60f3\u53d1\u6325\u5b83\u7684\u6700\u5927\u529f\u6548\uff0c\u8fd8\u662f\u5f97\u5b66\u4f1a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0cBulk Rename Utility \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u662f Perl Regular Expression\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u4f8b\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assume you have a file called&nbsp;Program Files, and you wish to swap the names around (e.g.&nbsp;Files Program). A Regular Expression which performs this task is :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u6587\u4ef6\u53eb\u505a&nbsp;Program Files&nbsp; \uff0c\u6211\u4eec\u60f3\u4ea4\u6362\u4e00\u4e0b\uff0c\u6539\u4e3a&nbsp;Files Program\uff0c\u90a3\u4e48Perl\u6b63\u5219\u8868\u8fbe\u5f0f\u5e94\u4e3a\uff1a\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>^([A-Z][a-z]*) ([A-Z][a-z]*)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let us break this down into components:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u8ba9\u6211\u4eec\u62c6\u89e3\u4e00\u4e0b\uff1a\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>^&nbsp;<\/strong>This means start at the beginning of the string<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010<strong>^<\/strong>\u610f\u601d\u662f\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>([A-Z][a-z]*)<\/strong>&nbsp;This is a single &#8220;group&#8221;, which we will use later. What this says is that we want any capital letter, followed by any number of lower-case letters. The single capital letter is denoted by the&nbsp;<strong>[A-Z]<\/strong>, i.e. allow a letter in the range A to Z. The lower-case letters are denoted by&nbsp;<strong>[a-z]<\/strong>&nbsp;in the same way, followed by an asterisk. This means we can allow any number of letters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010<strong>([A-Z][a-z]*)&nbsp;<\/strong>\u662f\u4e00\u4e2a\u72ec\u7acb\u201c\u7ec4\u201d\u3002\u5176\u542b\u4e49\u662f\uff1a\u6211\u4eec\u60f3\u627e\u5230\u6240\u6709\u5927\u5199\u5b57\u6bcd\uff0c\u8fd9\u4e9b\u5927\u5199\u5b57\u6bcd\u540e\u9762\u662f\u5c0f\u5199\u5b57\u6bcd\u3002\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\u7528&nbsp;<strong>[A-Z]&nbsp;<\/strong>\u4ee3\u8868\uff0c\u4e5f\u5c31\u662f\u5141\u8bb8A\u5230Z\u4e2d\u7684\u4efb\u4e00\u5927\u5199\u5b57\u6bcd\u3002\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u7528&nbsp;<strong>[a-z]&nbsp;<\/strong>\u4ee3\u8868\uff0c\u4e5f\u5c31\u662f\u5141\u8bb8a\u5230z\u7684\u4efb\u4e00\u5c0f\u5199\u5b57\u6bcd\u3002\u6700\u540e\u7684&nbsp;<strong>*&nbsp;<\/strong>\u661f\u6807\uff0c\u8868\u793a\u6211\u4eec\u53ef\u4ee5\u4e0d\u9650\u5236\u6ee1\u8db3\u4ee5\u4e0a\u6761\u4ef6\u7684\u5b57\u6bcd\u6570\u91cf\uff0c\u53ef\u4ee5\u662f\u4e00\u4e2a\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u4e2a\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We then allow a single space. If I had wanted multiple spaces I would probably have typed &#8220;space asterisk&#8221;, or possible ( *) to group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u7136\u540e\uff0c\u6211\u4eec\u5728\u7b2c\u4e00\u4e2a\u72ec\u7acb\u7ec4\u540e\u9762\u52a0\u4e00\u4e2a\u7a7a\u683c\u3002\u5982\u679c\u5e0c\u671b\u4e0d\u6b62\u4e00\u4e2a\u7a7a\u683c\uff0c\u90a3\u4e48\u5e94\u8be5\u7528\u201c\u7a7a\u683c+\u661f\u6807\u201d\uff0c\u5373&nbsp;( *)&nbsp;\u8868\u660e\uff0c\u8fd9\u91cc\u7528\u4e86\u62ec\u53f7\u8868\u793a\u53c8\u4e00\u4e2a\u72ec\u7acb\u7ec4\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We then have exactly the same again, i.e. we are denoting two words.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u518d\u7136\u540e\uff0c\u6211\u4eec\u91cd\u590d\u4e86\u7b2c\u4e00\u7ec4\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u7684\u76ee\u6807\u5bf9\u8c61\u662f\u4e24\u4e2a\u60c5\u51b5\u4e00\u6837\u7684\u5355\u8bcd\uff1aProgram Files&nbsp;\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Notice we had two sets of brackets. Everything within each set of brackets is treated as a &#8220;grouping&#8221;, and we refer to these groupings as&nbsp;<strong>\\1<\/strong>,&nbsp;<strong>\\2<\/strong>,&nbsp;<strong>\\3<\/strong>&nbsp;etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u6ce8\u610f\u6211\u4eec\u6709\u4e24\u5957\u62ec\u53f7\uff0c\u6bcf\u5bf9\u62ec\u53f7\u4e2d\u7684\u5185\u5bb9\u88ab\u89c6\u4e3a\u4e00\u4e2a\u201c\u5206\u7ec4\u201d\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u7528&nbsp;&nbsp;<strong>\\1<\/strong>,&nbsp;<strong>\\2<\/strong>,&nbsp;<strong>\\3<\/strong>&nbsp;&nbsp;\u6765\u5f15\u7528\u4ed6\u4eec\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, lets say we wanted to swap around the two words in the filename. We would put:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u8fd9\u6837\uff0c\u6211\u4eec\u7684\u4ea4\u6362\u8868\u8fbe\u5f0f\u4e2d\uff0c\u5339\u914d\u90e8\u5206\u5c31\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>^([A-Z][a-z]*) ([A-Z][a-z]*)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the match string, and<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u66ff\u6362\u90e8\u5206\u8fd9\u6837\u5199\uff1a\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\\2 \\1<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/static.oschina.net\/uploads\/space\/2012\/0217\/122101_HRPm_32037.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The above example is very precise. If we wanted to swap the first two words of a name, but keep the remaining text the same, we could put<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u4e0a\u9762\u7684\u4f8b\u5b50\u5f88\u7b80\u5355\uff0c\u5982\u679c\u6211\u4eec\u6709\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3a\uff1aProgram Files Directory&nbsp;\uff0c\u6211\u4eec\u53ea\u60f3\u4ea4\u6362\u524d\u4e24\u4e2a\u5355\u8bcd\uff0c\u5269\u4e0b\u7684\u90e8\u5206\u4fdd\u6301\u4e0d\u53d8\uff0c\u5373\u6210\u4e3a\uff1aFiles&nbsp;Program Directory\uff0c\u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u8fd9\u6837\u5199\uff1a\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>^([A-Z][a-z]*) ([A-Z][a-z]*)(.*)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\\2\\1\\3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This says to create three groups: the first group is the first word, the second group is the second word, and the third group is everything that&#8217;s left.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u610f\u601d\u662f\uff1a\u521b\u5efa\u4e09\u4e2a\u5206\u7ec4\uff0c\u7b2c\u4e00\u4e2a\u662f\u7b2c\u4e00\u4e2a\u5355\u8bcd\uff0c\u7b2c\u4e8c\u4e2a\u662f\u7b2c\u4e8c\u4e2a\u5355\u8bcd\uff0c\u7b2c\u4e09\u4e2a\u662f\u5269\u4f59\u7684\u4e1c\u897f\u3002\u3011<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.cnblogs.com\/onelikeone\/p\/15765259.html#_labelTop\">\u56de\u5230\u9876\u90e8<\/a><a><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><a href=\"https:\/\/my.oschina.net\/zhmsong\/blog\/40923\" target=\"_blank\" rel=\"noreferrer noopener\">Perl \u6b63\u5219\u8868\u8fbe\u5f0f \u5728 Bulk Rename Utility \u5b9e\u4f8b<\/a><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Bulk Rename Utility \u662f\u6709\u6548\u7684\u3001\u7b80\u6d01\u7684\u6587\u4ef6\u540d\u6279\u91cf\u66ff\u6362\u5de5\u5177\uff0c\u4f46\u5982\u679c\u60f3\u53d1\u6325\u5b83\u7684\u6700\u5927\u529f\u6548\uff0c\u8fd8\u662f\u5f97\u5b66\u4f1a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0cBulk Rename Utility \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u662f Perl Regu&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,18,15,19],"tags":[],"class_list":["post-264","post","type-post","status-publish","format-standard","hentry","category-win10","category-18","category-15","category-19"],"_links":{"self":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=264"}],"version-history":[{"count":1,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/264\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/264\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}