Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:35:19+00:00 2026-06-07T00:35:19+00:00

I would like to use R to extract the speaker out of scripts formatted

  • 0

I would like to use R to extract the speaker out of scripts formatted like in the following example:

“Scene 6: Second Lord: Nay, good my lord, put him to’t; let him have his way. First Lord: If your lordship find him not a hilding, hold me no more in your respect. Second Lord: On my life, my lord, a bubble. BERTRAM: Do you think I am so far deceived in him? Second Lord: Believe it, my lord, in mine own direct knowledge, without any malice, but to speak of him as my kinsman, he’s a most notable coward, an infinite and endless liar, an hourly promise-breaker, the owner of no one good quality worthy your lordship’s entertainment.”

In this example, I would like to extract: (“Second Lord”, “First Lord”, “Second Lord”, “BERTRAM”, “Second Lord”). The rule is obvious: it is the group of words situated between the end of a sentence and a semi-column.

How can I write this in R ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:35:21+00:00Added an answer on June 7, 2026 at 12:35 am

    Maybe something like this:

    library(stringr)  
    body <- "Scene 6: Second Lord: Nay, good my lord, put him to't; let him have his way. First Lord: If your lordship find him not a hilding, hold me no more in your respect. Second Lord: On my life, my lord, a bubble. BERTRAM: Do you think I am so far deceived in him? Second Lord: Believe it, my lord, in mine own direct knowledge, without any malice, but to speak of him as my kinsman, he's a most notable coward, an infinite and endless liar, an hourly promise-breaker, the owner of no one good quality worthy your lordship's entertainment." 
    p <- str_extract_all(body, "[:.?] [A-z ]*:")
    
    # and get rid of extra signs
    p <- str_replace_all(p[[1]], "[?:.]", "")
    # strip white spaces
    p <- str_trim(p)
    p
    "Second Lord" "First Lord"  "Second Lord" "BERTRAM"     "Second Lord"
    
    # unique players
    unique(p)
    [1] "Second Lord" "First Lord"  "BERTRAM"  
    

    Explanations of regex: (which are not perfect)

    str_extract_all(body, "[:.?] [A-z ]*:") a match is started with either : or . or ? ([:.?]) followed by a whitespace. Any character and whitespace is matched until the next :.

    Get position

    You can use str_locate_all with the same regex:

    str_locate_all(body, "[:.?] [A-z ]*:")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use Python to extract content formatted in MediaWiki markup following
I would like to use the wikipedia API to return the extract from multiple
I would like to use a regular expression to extract bind variable parameters from
I would like to use the subset function in R to extract smaller groups
I would like to use regular expression to extract only @patrick @michelle from the
I would like to use XPath to extract the ImageUID element value (i.e.{7f2535d0-9a41-4997-9694-0a4de569e6d9}) and
I would like to use LINQ to solve the following problem, I have the
I have an array of Integers in Java, I would like use only a
I would like to use Maven's password encryption such as it uses for nodes
I would like to use the logout function from Django but not sure how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.