我正在尝试创建一个正则表达式来查找和替换(保留为空)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.¨:
文本中的名字(不是说话的人)也消失了/删除了。
是否可以仅使用一个正则表达式进行清理?
答案 0 :(得分:1)
您可以使用
function hello(param) {
if (typeof param == 'undefined')
param = true;
// or
param = param || true;
...
}
请参见regex demo
详细信息
(?m)^\*?[A-Z][\w' -]*:\s*
-(?m)
标志,它使re.M
匹配一行的开头^
-一行的开头^
-可选的\*?
字符*
-大写字母[A-Z]
-0个或多个单词字符,空格,[\w' -]*
或撇号-
-冒号:
-超过0个空格。