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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:09:40+00:00 2026-05-26T01:09:40+00:00

I am trying to using Python’s re.sub() to match a string with an e

  • 0

I am trying to using Python’s re.sub() to match a string with an e character and insert curly braces immediately after the e character and after the lastdigit. For example:

12.34e56 to 12.34e{56}
1e10 to 1e{10}

I can’t seem to find the correct regex to insert the desired curly braces. For example, I can properly insert the left brace like this:

>>> import re
>>> x = '12.34e10'
>>> pattern = re.compile(r'(e)')
>>> sub = z = re.sub(pattern, "\1e{", x)
>>> print(sub)
    12.34e{10 # this is the correct placement for the left brace

My problem arises when using two back references.

>>> import re
>>> x = '12.34e10'
>>> pattern = re.compile(r'(e).+($)')
>>> sub = z = re.sub(pattern, "\1e{\2}", x)
>>> print(sub)
    12.34e{} # this is not what I want, digits 10 have been removed

Can anyone point out my problem? Thanks for the help.

  • 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-26T01:09:40+00:00Added an answer on May 26, 2026 at 1:09 am
    re.sub(r'e(\d+)', r'e{\1}', '12.34e56')
    

    returns '12.34e{56}'

    or, the same result but different logic (don’t replace e with e):

    re.sub(r'(?<=e)(\d+)', r'{\1}', '12.34e56')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using python and I'm simply trying to split a string on white characters
I am trying to split string data using Python which is delimited by the
Using Python, I'm trying to parse a string like this: hello I am an
I am trying to insert a bunch of strings into mysql using python and
I am using Python 2.6 and am trying to run a simple random number
I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
I am trying to talk to a device using python. I have been handed
i m trying to design a mmo game using python... I have evaluated stackless
Im trying to download share data from a stock exchange using python. The problem
I have been trying to make a case for using Python at my work.

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.