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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:40:33+00:00 2026-06-02T08:40:33+00:00

I need to perform a search/replace on text which contains a comma which is

  • 0

I need to perform a search/replace on text which contains a comma which is NOT followed by a space, to change to a comma+space.

So I can find this using:

,[^\s]

But I am struggling with the replacement; I can’t just use:

 , (space, comma)

Or

& ,

As the match originally matches two characters.

Is there a way of saying ‘&’ – 1 ? or ‘&[0]’ or something which means; ‘The Matched String, but only part of it’ in the replacement argument ?

Another way of trying to ask this:

  1. Can I use Regex to IDENTIFY one part of my string.
  2. But REPLACE a (slightly different,but related) part of my string.

I could just probably replace every comma with a comma+space, but this is a little more controlled and less likely to make a change I do not need….

For example:

Original:

Hello,World.

Should become:

Hello, World.

But:

Hello, World.

Should remain as :

Hello, World.

And currently, using my (bad) pattern I have:

Original:

Hello,World

After (wrong):

Hello, orld

I’m actually using Python’s (2.6) ‘re’ module for this as it happens.

  • 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-02T08:40:34+00:00Added an answer on June 2, 2026 at 8:40 am

    Using parantheses to capture a part of the string is one way to do it. Another possibility is to use “lookahead assertion”:

    ,(?=\S)
    

    This pattern matches a comma only if it is followed by a non-whitespace character. It does not match anything followed by comma but uses that information to decide whether or not to match the comma.

    For example:

    >>> re.sub(r",(?=\S)", ", ", "Hello,World! Hello, World!")
    'Hello, World! Hello, World!'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to perform a find and replace using XSLT 1.0 which is really
I have a need to perform search and replace operations on large blocks of
I'm trying to perform a search-replace in several JCLs but I need multi-line capabilities,
I have a set of data on which I need to perform a topological
I'm new to ASP.NET MVC, but I need to perform a search for articles
If I want to perform a search on a directory that contains thousands of
I need to perform a search operation into my SQLite DB. In my Activity,
I need to perform google search to retrieve the number of results for a
I need to perform a regular expression search for a string x in another
I need to perform deletion of the document from lucene search index. Standard approach

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.