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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:08:27+00:00 2026-06-16T21:08:27+00:00

I’m having a problem in replacing chars in string using python’s 3 regex. I

  • 0

I’m having a problem in replacing chars in string using python’s 3 regex. I am able to find the pattern occurrences, but I want to replace a char that appears as first in the pattern. Unfortunately I’m replacing the whole pattern. On the other hand – I might be wrong in using regex for this task at all. Here is what I have:

>>> my_table1='\nParametr JednostkaNormaGodzinaŚrednia(1)123456789101112131415161718192021222324 \nDwutlenek siarki (SO2) µg/m3 350 56 53 50 51 51 44 41 36 39 42 34 30 34 33 26 25 24 23 24 25 21 21 22 24 35 \nTlenek azotu (NO) µg/m3 30 30 27 29 44 98 192

What I want to do is to insert ‘,’ or ‘;’ between the numbers. I can not simply replace all spaces with comma as I do not want to split this part: \nDwutlenek siarki (SO2) µg/m3. So I figured to find occurrences of space and digits using regex (r'\s\d+'). This finds all instances correctly. Now I wanted to use the sub function to replace the \s with ‘,’ but I do not know how to isolate just \s from the pattern. Any ideas?

  • 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-16T21:08:29+00:00Added an answer on June 16, 2026 at 9:08 pm

    Use lookbehind/lookahead, like this:

    p = re.compile(r'(?<=\d)\s(?=\d)')
    p.sub(';', my_table1)
    

    Positive lookbehind (?<=\d) matches anything after a digit (\d) without matching the digit itself; \s matches a single whitespace character; and positive lookahead (?=\d) matches anything that is followed by a digit. So this replaces any single whitespace between two digits with a ;. Note that the lookbehind/ahead needs to be fixed length (so you can’t use things like (?<=\d+)).

    In your case it should be enough with just r'\s(?=\d)' though, may not need the lookbehind.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I want to construct a data frame in an Rcpp function, but when I
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.