Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Komodo中使用replace regex?_Python_Regex_Komodo - Fatal编程技术网

Python 如何在Komodo中使用replace regex?

Python 如何在Komodo中使用replace regex?,python,regex,komodo,Python,Regex,Komodo,我试图创建一个正则表达式来查找和替换txt文件中的不同名称(保持为空)。我使用科莫多,因为它是考试的一部分 下面是文本示例: *Cassidy: What's your name again? Chrissie Watkins: Chrissie! Cassidy: Where are we going? Chrissie: Swimming! Cassidy: Slow up, slow down! I'm not drunk! Slow down! Wait I'm coming! I'm

我试图创建一个正则表达式来查找和替换txt文件中的不同名称(保持为空)。我使用科莫多,因为它是考试的一部分

下面是文本示例:

*Cassidy: What's your name again?
Chrissie Watkins: Chrissie!
Cassidy: Where are we going?
Chrissie: Swimming!
Cassidy: Slow up, slow down! I'm not drunk! Slow down! Wait I'm coming! I'm
coming! I'm definitely 
coming! Wait, slow up! I can swim -- just can't walk or dress myself.
Chrissie: Come on in the water!
Cassidy: Take it easy. Take it easy.
Chrissie: Oh! God help me! God! Argh! God help!
Cassidy: I'm coming... I'm coming.
Chrissie: It hurts! It hurts! Oh my god! God help me! God please help!
Martin Brody: How come the sun didn't use to shine in here.
Ellen Brody: We bought the house in the fall, this is summer.
Ellen: Somebody feed the dogs, huh?
Martin: Right.
Ellen: See the kids?
Martin: They must be in the backyard.
Ellen: In Amity, you say: yahd.
必须清除文本,这意味着必须删除每行开头的所有名称(不替换任何内容)

如果我使用此选项:\w.¨:

此外,文本中的姓名(不是说话的人)也会消失/删除

是否可以只使用一个正则表达式进行清理?

您可以使用

(?m)^\*?[A-Z][\w' -]*:\s*

详细信息

  • (?m)
    -
    re.m
    标志,它使
    ^
    匹配行的开头
  • ^
    -行的开头
  • \*?
    -可选的
    *
    字符
  • [A-Z]
    -大写字母
  • [\w'-]*
    -0个或多个单词字符、空格、
    -
    或撇号
  • -冒号
  • \s*
    -0+空格

试试
(?m)^\*?[A-Z][\w'-]*:\s*
,看你真棒!我不知道你的前注册码是什么意思,但我会尽力弄清楚!!我现在已经看过Wiktor演示-谢谢!!