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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:32:03+00:00 2026-06-03T02:32:03+00:00

I have some strings in python , like: 1) ‘a_1_2+c_2_4 + 5’ 2) ‘ctl_1_3/80’

  • 0

I have some strings in python, like:

1) 'a_1_2+c_2_4 + 5'
2) 'ctl_1_3/80'
3) 'd_10_55'
...

I want to replace them with re. They should look like:

1) 'p.get("a_1_2", 0)+p.get("c_2_4", 0) + 5'
2) 'p.get("ctl_1_3", 0)/80'
3) 'p.get("d_10_55", 0)'

Can you help me with regular expression?

P.S. p is simple dict in python

  • 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-03T02:32:04+00:00Added an answer on June 3, 2026 at 2:32 am
    In [7]: s = 'a_1_2+c_2_4 + 5'
    
    In [8]: re.sub(r'(\w+_\d+_\d+)', r'p.get("\1", 0)', s)
    Out[8]: 'p.get("a_1_2", 0)+p.get("c_2_4", 0) + 5'
    

    It’s unclear what rules govern the second argument to p.get(). It is present in the first example but not the other two.

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

Sidebar

Related Questions

I have some LINQ code that generates a list of strings, like this: var
I'm trying to rewrite some query strings I have in my URL like this
I currently have some python code I'd like to port to C++ as it's
I have several strings which look like the following: <some_text> TAG[<some_text>@11.22.33.44] <some_text> I want
I have run into a problem joining two strings in Python. I have some
Let's say you want to start a python script with some parameters like python
Does Objective-C have raw strings like Python's ? Clarification: a raw string doesn't interpret
I have some strings which starts with dots, and I want to delete it.
I have some code in a python string that contains extraneous empty lines. I
I have some C code that stores ASCII strings in memory as a four

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.