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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:47:00+00:00 2026-05-22T23:47:00+00:00

The following is a sample string I will be searching which will be on

  • 0

The following is a sample string I will be searching which will be on a separate line with other strings:

Chapter 1: My name is: Shojib (aka mhs)

Here is my regular expression to find that particular line: (Chapter)( )([0-9])(:)( .*)

Now I want to keep the words and integers, and remove the punctuation, and separate each words and integers with an underscore. For example, this is how the format should look after replacing:

Chapter_1_My_name_is_Shojib_aka_mhs

  • 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-22T23:47:01+00:00Added an answer on May 22, 2026 at 11:47 pm

    Because you didn’t mention the language, this answer is using Perl notation. The exact replace syntax depends on your used language.

    You need to do it with two regexes. The first one that removes the punctuation and the second one to replace the whitespace with underscores.

    s/[^\w\s]//g
    

    Means match [^\w\s] and replace it with ”. \w a word character (contains different characters depending on your regex engine at least 0-9a-zA-Z_ if your language supports Unicode it can be that all letters are in \w)

    \s a whitespace character

    [] a character class

    ^ at the first position inside a character class is the negation

    [^\w\s] all characters that are not \w and \s

    This will replace anything that is not a word character and not a whitespace with nothing.

    The second step is to replace the remaining whitespace with _

    s/\s/_/g
    

    Your regex (Chapter)( )([0-9])(:)( .*) to find your row can also be improved. If you use brackets, you create capturing groups, that means the matched pattern is stored into a variable. So it makes no sense to search for Chapter and store this into a variable, its already known. if you don’t need those variables you can reduce your regex to:

    Chapter\s*\d:.*
    

    \d is the same than [0-9]

    \s* means any amount of whitespace

    Do you expect chapter numbers bigger than 9? Then use

    Chapter\s*\d+:.*
    

    + means at least one, so \d+ will match on at least one digit.

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

Sidebar

Related Questions

Kindly provide me a sample code which will contain the following: ListView in which
I have the following sample code which doesn't seem to want to run. import
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I wrote ASP.NET pages which will manage forms. They're based on the following base
In the following sample, the writer of the derived class will be expected to
I have a string that has the following format: string sample = A, ABC,
Considering the following sample XAML file, which shows the first 1000 people of Facebook,
Given the following simple example: List<string> list = new List<string>() { One, Two, Three,
I needed some simple string encryption, so I wrote the following code (with a
Simple regex question. I have a string on the following format: this is a

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.