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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:31:30+00:00 2026-06-09T14:31:30+00:00

Consider a basic regex like a(.+?)a . How can one replace all occurences of

  • 0

Consider a basic regex like a(.+?)a. How can one replace all occurences of that regex in a file with the content of the first group?

  • 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-09T14:31:32+00:00Added an answer on June 9, 2026 at 2:31 pm

    Use can use the re module to use regular expressions in python and the fileinput module to simply replace text in files in-place


    Example:

    import fileinput
    import re
    
    fn = "test.txt" # your filename
    
    r = re.compile('a(.+?)a')
    for line in fileinput.input(fn, inplace=True):
      match = r.match(line)
      print match.group() if match else line.replace('\n', '')
    

    Before:

    hello this
    aShouldBeAMatch!!!!! and this should be gone
    you know

    After:

    hello this
    aShouldBeAMa
    you know


    Note: this works because the argument inplace=True causes input file to be moved to a backup file and standard output is directed to the input file, as documented under Optional in-place filtering.

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

Sidebar

Related Questions

Consider a basic Rails development pipeline, going from development -> staging -> production. When
Consider a basic addEventListener as window.onload=function(){ document.getElementById(alert) .addEventListener('click', function(){ alert(OK); }, false); } where
Consider I have a game-creation framework, with a basic class called Game. // Action
This is a very basic question, so please bear with me. Consider the following
Consider having the following header file (c++): myclass.hpp #ifndef MYCLASSHPP_ #define MYCLASSHPP_ namespace A
Let's consider this basic insert insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3) i want this
consider the following basic class layout: public class Base : IComparable<Base> { public int
I've got some basic questions about C++. Consider the following code in which I
My basic question is: How can I force Hibernate to make float NULLable and
For ease of discussion, consider this basic table (Test) in Access... ID division name

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.