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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:53:47+00:00 2026-05-22T19:53:47+00:00

I have a section of code that I need to remove from multiple files

  • 0

I have a section of code that I need to remove from multiple files that starts like this:

<?php
//{{56541616

and ends like this:

//}}18420732
?>

where both strings of numbers can be any sequence of letters and numbers (not the same).

I wrote a Python program that will return the entire input string except for this problem string:

def removeInsert(text):
    m = re.search(r"<\?php\n\/\/\{\{[a-zA-Z0-9]{8}.*\/\/\}\}[a-zA-Z0-9]{8}\n\?>", text, re.DOTALL)
    return text[:m.start()] + text[m.end():]

This program works great when I call it with removeInsert(“””[file text]”””) — the triple quotes allow it to be read in as multiline.

I attempted to extend this to open a file and pass the string contents of the file to removeInsert() with this:

def fileRW(filename):
    input_file = open(filename, 'r')
    text = input_file.read()
    newText = removeInsert(text)
    ...

However, when I run fileRW([input-file]), I get this error:

return text[:m.start()] + text[m.end():]
AttributeError: 'NoneType' object has no attribute 'start'

I can confirm that “text” in that last code is actually a string, and does contain the problem code, but it seems that the removeInsert() code doesn’t work on this string. My best guess is that it’s related to the triple quoting I do when inputting the string manually into removeInsert(). Perhaps the text that fileRW() passes to removeInsert() is not triple-quoted (I’ve tried different ways of forcing it to have triple quotes (“\”\”\”” added), but that doesn’t work). I have no idea how to fix this, though, and can’t find any information about it in my google searching. Any suggestions?

  • 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-22T19:53:48+00:00Added an answer on May 22, 2026 at 7:53 pm

    Your regex only uses \n for lines. Your text editor may insert a carriage return and newline combination: \r\n. Try changing \n in your regex to (\r\n|\r|\n).

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

Sidebar

Related Questions

I have a section of code that is being used to determine if a
I have a section of makefile that has this sort of structure: bob: ifdef
Currently I have a section of code that needs to make about 7 web
I have a section of code that depending on the URL requested, will include
I have the following code that uses Sequence objects to read data from a
I have a section of Razor code in one of my views that isn't
Okay, this is more for my own learning than actual need. I have files
I have following Code Block Which I tried to optimize in the Optimized section
I have a section: \section{Introduction} \label{sec:introduction} I'd like a link to the section where
I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't

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.