简体   繁体   English

如何在Komodo中使用replace regex?

[英]How to use replace regex in Komodo?

I am trying to create a regex to find and replace (keep empty) different names in an txt file. 我正在尝试创建一个正则表达式来查找和替换(保留为空)txt文件中的其他名称。 I use Komodo, as it is part of the examen. 我使用Komodo,因为它是应试的一部分。

Here the text sample: 这里是文本示例:

*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.

The text must be cleaned up, meaning all names at the beginning of each line must be deleted (replaced by nothing). 必须清除文本,这意味着必须删除每行开头的所有名称(不替换任何内容)。

If I use this: \\w.¨: 如果使用此命令:\\w.¨:

Also names in texts (not the person speaking) are gone / deleted. 文本中的名称(不是说话的人)也被删除。

Is it possible to use just one regular expression for cleaning up? 是否可以仅使用一个正则表达式进行清理?

You may use 您可以使用

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

See the regex demo 正则表达式演示

Details 细节

  • (?m) - re.M flag, it makes ^ match start of a line (?m) re.M标志,它使^匹配行的开头
  • ^ - start of a line ^ -一行的开始
  • \\*? - an optional * char -可选的*字符
  • [AZ] - an uppercase letter [AZ] -大写字母
  • [\\w' -]* - 0 or more word chars, spaces, - or apostrophes [\\w' -]* -0个或多个单词字符,空格或-或撇号
  • : - a colon : -冒号
  • \\s* - 0+ whitespaces. \\s* -0+个空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM