[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] Python无法做到中文匹配替换,英语字母没问题

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. import re
  4. str = '''TITLE "Leslie Cheung 张国荣 LPCD45"
  5. PERFORMER "张国荣"
  6. REM DATE "2008"
  7. REM DISCID E3103E10
  8. FILE "Leslie Cheung 张国荣 LPCD45.flac" WAVE
  9.   TRACK 01 AUDIO
  10.     TITLE "奔向未来日子"
  11.     PERFORMER "张国荣"
  12.     REM COMMENT "[www.pt80.net]"
  13.     INDEX 01 00:00:00
  14.   TRACK 02 AUDIO
  15.     TITLE "由零开始"
  16.     PERFORMER "张国荣"
  17.     REM COMMENT "[www.pt80.net]"
  18.     INDEX 00 04:29:50
  19.     INDEX 01 04:34:50
  20.   TRACK 03 AUDIO
  21.     TITLE "这是爱"
  22.     PERFORMER "张国荣"
  23.     REM COMMENT "[www.pt80.net]"
  24.     INDEX 00 08:41:70
  25.     INDEX 01 08:46:70
  26.   TRACK 04 AUDIO
  27.     TITLE "似水流年"
  28.     PERFORMER "张国荣"
  29.     REM COMMENT "[www.pt80.net]"
  30.     INDEX 00 12:28:42
  31.     INDEX 01 12:33:42
  32.   TRACK 05 AUDIO
  33.     TITLE "情难自控"
  34.     PERFORMER "张国荣"
  35.     REM COMMENT "[www.pt80.net]"
  36.     INDEX 00 16:50:17
  37.     INDEX 01 16:55:17
  38.   TRACK 06 AUDIO
  39.     TITLE "你在何地"
  40.     PERFORMER "张国荣"
  41.     REM COMMENT "[www.pt80.net]"
  42.     INDEX 00 21:09:35
  43.     INDEX 01 21:14:35
  44.   TRACK 07 AUDIO
  45.     TITLE "烈火灯蛾"
  46.     PERFORMER "张国荣"
  47.     REM COMMENT "[www.pt80.net]"
  48.     INDEX 00 26:16:41
  49.     INDEX 01 26:21:41
  50.   TRACK 08 AUDIO
  51.     TITLE "浓情"
  52.     PERFORMER "张国荣"
  53.     REM COMMENT "[www.pt80.net]"
  54.     INDEX 00 30:37:65
  55.     INDEX 01 30:42:65
  56.   TRACK 09 AUDIO
  57.     TITLE "想你"
  58.     PERFORMER "张国荣"
  59.     REM COMMENT "[www.pt80.net]"
  60.     INDEX 00 34:16:59
  61.     INDEX 01 34:21:59
  62.   TRACK 10 AUDIO
  63.     TITLE "雪中情"
  64.     PERFORMER "张国荣"
  65.     REM COMMENT "[www.pt80.net]"
  66.     INDEX 00 39:16:50
  67.     INDEX 01 39:21:50
  68.   TRACK 11 AUDIO
  69.     TITLE "风再起时"
  70.     PERFORMER "张国荣"
  71.     REM COMMENT "[www.pt80.net]"
  72.     INDEX 00 43:22:08
  73.     INDEX 01 43:27:08
  74.   TRACK 12 AUDIO
  75.     TITLE "沉默是金"
  76.     PERFORMER "张国荣"
  77.     REM COMMENT "[www.pt80.net]"
  78.     INDEX 00 47:55:56
  79.     INDEX 01 48:00:56
  80.   TRACK 13 AUDIO
  81.     TITLE "共同渡过"
  82.     PERFORMER "张国荣"
  83.     REM COMMENT "[www.pt80.net]"
  84.     INDEX 00 52:07:62
  85.     INDEX 01 52:12:62
  86.   TRACK 14 AUDIO
  87.     TITLE "寂寞夜晚"
  88.     PERFORMER "张国荣"
  89.     REM COMMENT "[www.pt80.net]"
  90.     INDEX 00 56:35:65
  91.     INDEX 01 56:40:65
  92.   TRACK 15 AUDIO
  93.     TITLE "无需要太多"
  94.     PERFORMER "张国荣"
  95.     REM COMMENT "[www.pt80.net]"
  96.     INDEX 00 61:05:07
  97.     INDEX 01 61:10:07
  98.   TRACK 16 AUDIO
  99.     TITLE "倩女幽魂"
  100.     PERFORMER "张国荣"
  101.     REM COMMENT "[www.pt80.net]"
  102.     INDEX 00 65:36:17
  103.     INDEX 01 65:41:16'''
  104. print re.sub(r'REM COMMENT "[www.pt80.net]"','',str);
复制代码
应该如何修改呢?
我想把 REM COMMENT "[www.pt80.net]"这些行去掉。

回复 1# netdzb
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. import re
  4. str = '''TITLE "Leslie Cheung 张国荣 LPCD45"
  5. PERFORMER "张国荣"
  6. REM DATE "2008"
  7. REM DISCID E3103E10
  8. FILE "Leslie Cheung 张国荣 LPCD45.flac" WAVE
  9.   TRACK 01 AUDIO
  10.     TITLE "奔向未来日子"
  11.     PERFORMER "张国荣"
  12.     REM COMMENT "[www.pt80.net]"
  13.     INDEX 01 00:00:00
  14.   TRACK 02 AUDIO
  15.     TITLE "由零开始"
  16.     PERFORMER "张国荣"
  17.     REM COMMENT "[www.pt80.net]"
  18.     INDEX 00 04:29:50
  19.     INDEX 01 04:34:50
  20.   TRACK 03 AUDIO
  21.     TITLE "这是爱"
  22.     PERFORMER "张国荣"
  23.     REM COMMENT "[www.pt80.net]"
  24.     INDEX 00 08:41:70
  25.     INDEX 01 08:46:70
  26.   TRACK 04 AUDIO
  27.     TITLE "似水流年"
  28.     PERFORMER "张国荣"
  29.     REM COMMENT "[www.pt80.net]"
  30.     INDEX 00 12:28:42
  31.     INDEX 01 12:33:42
  32.   TRACK 05 AUDIO
  33.     TITLE "情难自控"
  34.     PERFORMER "张国荣"
  35.     REM COMMENT "[www.pt80.net]"
  36.     INDEX 00 16:50:17
  37.     INDEX 01 16:55:17
  38.   TRACK 06 AUDIO
  39.     TITLE "你在何地"
  40.     PERFORMER "张国荣"
  41.     REM COMMENT "[www.pt80.net]"
  42.     INDEX 00 21:09:35
  43.     INDEX 01 21:14:35
  44.   TRACK 07 AUDIO
  45.     TITLE "烈火灯蛾"
  46.     PERFORMER "张国荣"
  47.     REM COMMENT "[www.pt80.net]"
  48.     INDEX 00 26:16:41
  49.     INDEX 01 26:21:41
  50.   TRACK 08 AUDIO
  51.     TITLE "浓情"
  52.     PERFORMER "张国荣"
  53.     REM COMMENT "[www.pt80.net]"
  54.     INDEX 00 30:37:65
  55.     INDEX 01 30:42:65
  56.   TRACK 09 AUDIO
  57.     TITLE "想你"
  58.     PERFORMER "张国荣"
  59.     REM COMMENT "[www.pt80.net]"
  60.     INDEX 00 34:16:59
  61.     INDEX 01 34:21:59
  62.   TRACK 10 AUDIO
  63.     TITLE "雪中情"
  64.     PERFORMER "张国荣"
  65.     REM COMMENT "[www.pt80.net]"
  66.     INDEX 00 39:16:50
  67.     INDEX 01 39:21:50
  68.   TRACK 11 AUDIO
  69.     TITLE "风再起时"
  70.     PERFORMER "张国荣"
  71.     REM COMMENT "[www.pt80.net]"
  72.     INDEX 00 43:22:08
  73.     INDEX 01 43:27:08
  74.   TRACK 12 AUDIO
  75.     TITLE "沉默是金"
  76.     PERFORMER "张国荣"
  77.     REM COMMENT "[www.pt80.net]"
  78.     INDEX 00 47:55:56
  79.     INDEX 01 48:00:56
  80.   TRACK 13 AUDIO
  81.     TITLE "共同渡过"
  82.     PERFORMER "张国荣"
  83.     REM COMMENT "[www.pt80.net]"
  84.     INDEX 00 52:07:62
  85.     INDEX 01 52:12:62
  86.   TRACK 14 AUDIO
  87.     TITLE "寂寞夜晚"
  88.     PERFORMER "张国荣"
  89.     REM COMMENT "[www.pt80.net]"
  90.     INDEX 00 56:35:65
  91.     INDEX 01 56:40:65
  92.   TRACK 15 AUDIO
  93.     TITLE "无需要太多"
  94.     PERFORMER "张国荣"
  95.     REM COMMENT "[www.pt80.net]"
  96.     INDEX 00 61:05:07
  97.     INDEX 01 61:10:07
  98.   TRACK 16 AUDIO
  99.     TITLE "倩女幽魂"
  100.     PERFORMER "张国荣"
  101.     REM COMMENT "[www.pt80.net]"
  102.     INDEX 00 65:36:17
  103.     INDEX 01 65:41:16'''
  104. print re.sub('\n    REM COMMENT "\[www.pt80.net\]"','',str)
复制代码
我只能说是能力问题。。。

TOP

回复 1# netdzb

刚才试过了,中文也是可以匹配替换的。就是我要替换的这行不可以,不知道为什么?

TOP

返回列表