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 7771453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:39:24+00:00 2026-06-01T16:39:24+00:00

might be an easy question but i’m fairly new to regular expressions. given a

  • 0

might be an easy question but i’m fairly new to regular expressions.

given a paragraph, i would like to locate a particular sentence that begins with the specified word and replace the entire sentence with something else.

how can i build a regexp to search for a sentence that begins with a particular word, which can be followed by a number of different words, and ends with a . (period).

for example, given the sentence foo bar. foo3 bar3. foo2 bar2., find a substring that begins with foo3, has any number of words, and ends with ..

  • 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-01T16:39:25+00:00Added an answer on June 1, 2026 at 4:39 pm

    Something like this:

    /(^|\.\s+)(foo3[^.]*\.)/
    

    Searches for the period marking the previous sentence (or the beginning of the string in the case of the first sentence), followed by spaces, then the start character sequence (in this case, foo3), followed by all non-period characters leading up to the period ending that sentence.

    Demo: http://www.rubular.com/r/ROl2odiDn5


    Here’s how replacing the sentence might be implemented in practice:

    var str = "foo bar. foo3 bar3. foo2 bar2.";
    var regex = /(^|\.\s+)(foo3[^.]*\.)/g;
    str = str.replace(regex, "$1new sentence.");
    alert(str);
    

    In this example, I use the regular expression replace and incorporate the extra matched characters (period from previous sentence) via $1, followed by the new sentence that is to replace the old sentence. This ensures that the state of the other sentences in the paragraph remains unchanged. Note also that this example will update all matching sentences, since I use the /g(global) flag. If you only want to change the first sentence, remove the g, or make your sentence matching more specific by including more beginning words.

    Demo: http://jsfiddle.net/qPxFp/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a really easy question but I would like to grab the
This might be an easy question, but I'd like your help with this. I
this is might be a very basic question, but seems like it's not easy
This might seem an easy question for some, but I am struggling with it.
might be a stupid question but I seem to be confused. Im pretty new
Seems like this might be easy, but from reading other SO answers there are
I know this might be an easy question but still: I got a dropdown
This might be an easy question, but I am trying to come up with
This might be an easy question, but I cannot figure out why the compiler
I'm a newbie with PHP so this might be ridiculously easy question, but despite

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.