我正在尝试创建一个正则表达式来查找和替换txt文件中的不同名称(保持为空)。我用Komodo,因为它是考试的一部分。你知道吗
下面是文本示例:
*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.¨:
文本中的名字(不是说话的人)也会消失/删除。你知道吗
是否可以只使用一个正则表达式进行清理?你知道吗
你可以用
参见regex demo
细节
(?m)
-re.M
标志,它使^
匹配行的开头^
-行首\*?
-可选的*
字符[A-Z]
-大写字母[\w' -]*
-0个或多个单词字符、空格、-
或撇号:
-冒号\s*
-0+空格。你知道吗相关问题 更多 >
编程相关推荐