Tim
Tim

Reputation: 3

Regex to remove all quote-parts from a text?

I have a film script and I need to remove all quotes, thus the parts where people are saying something, f.e.: "Martin:". Does someone know which regex I shoud use?

I'm using scripting language Perl. So the input I have is a whole filmscript. The output I want is that filmscript but without the parts where people talk. So "Martin: I'm hungry." should turn into "I'm hungry."

I tried "\w+\b:" in the find-bar but that selects all instances with a : in it. I tried to use ^ to mark the beginning of the line but it gave an error.

Hower names are not always single names. They can also be Scout Leader or Kid #1 , for example.

Upvotes: -1

Views: 42

Answers (2)

Code Maniac
Code Maniac

Reputation: 37757

You can try this

^"[\w\s\d#]+:\s*

Explanation

^ - Match the start of string.

"[a-zA-Z][\w\s\d#]+: - Matches " followed by one or more alphabet or space or digit or #followed by :.

-\s* - Matches zero or more space character.

Demo

Upvotes: 1

Ángela
Ángela

Reputation: 1425

If the name never contains :, you could simply exclude it from the search (based on @code-maniac's answer):

^"[^:]+:\s*

Demo

[^:] matches any characters that are not :. You can include any characters that you do not want to match between the [].

Upvotes: 0

Related Questions