Muhammad Al-Saqri
Muhammad Al-Saqri

Reputation: 47

Regular expression for returning lines of dialogue

-I am a beginner python coder so bear with me!

what i have so far is,

def q_4():
  pattern = r'^\"\w*\"'
  return re.compile(pattern, re.M|re.IGNORECASE)

but for some reason it only returns one instance with one word between the two double quotes. How can i go about grasping full lines?

Upvotes: 1

Views: 139

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521804

Try searching on the pattern \"[^"]+\":

inp = """Here is a quote: "the quick brown fox jumps over
the lazy dog" and here is another "blah
blah blah" the end"""

dialogs = re.findall(r'\"([^"]+)\"', inp)
print(dialogs)

This prints:

['the quick brown fox jumps over\nthe lazy dog', 'blah\nblah blah']

Upvotes: 1

Related Questions