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

  • Home
  • SEARCH
  • 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 4585246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:28:04+00:00 2026-05-21T21:28:04+00:00

I need to insert a word after every X (i.e. 4,5,6 etc) sentences in

  • 0

I need to insert a word after every X (i.e. 4,5,6 etc) sentences in given text. I feel regex would be compact and good solution. To be specific, I need to do this in .net.

Thanks,

Mihir

(If regex can’t identify some sentences ending with not so common punctuation, I am fine with it. I don’t need 100% accuracy)

  • 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-05-21T21:28:05+00:00Added an answer on May 21, 2026 at 9:28 pm

    You can only do it with the Regex in .NET if you find a match and loop through the string as long as you find new matches. Of course this is no regex-only implementation:

    string word = "WORD"; // Your word
    string sentence = "1. 2. 3. 4. 5. 6. 7. 8. 9. 10."; // Your sentence
    long count = 0;
    int xSentence = 3; // Numbers of sentence
    int pos = 0;
    
    // Your Regex
    Regex reg = new Regex(@"[\.,\!,\?]", RegexOptions.IgnoreCase);
    Match mat = reg.Match(sentence);
    
    // While there is a new match
    while (mat.Success)
    {
        count++;
        if (count % xSentence == 0)
        {
            // +1 to insert the word after punctuation
            pos = mat.Index + 1;
    
            sentence = sentence.Insert(pos, word);
            mat = reg.Match(sentence, pos);
        }
        else
        {
            mat = mat.NextMatch();
        }
    }
    

    Maybe this woul help you implementing it in .NET although there are several other ways to do it.

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

Sidebar

Related Questions

How using VSTO and Word 2003 can I insert text after a table I've
now i need to insert some data from the sqlserver into a word,i know
Given a list of mailing addresses, I need to open an existing Word document,
I need to insert records into a table that has no primary key using
Basically I need to insert a bunch of data to an Excel file. Creating
I am currently working in C#, and I need to insert a new record
I am making a CSS file for an XML document. I need to insert
I need to be able to insert/update objects at a consistent rate of at
I need to create an SQL query to insert some data into a table
I need a quick no for DELETE/UPDATE/INSERT, since 3p reporting tool allows users to

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.