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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:43+00:00 2026-06-10T00:33:43+00:00

I am trying to do the following in python. I have a file with

  • 0

I am trying to do the following in python.

I have a file with the following content…

<VirtualHost>
  ServerName blah.com
  DocumentRoot /var/www/blah.com
</Virtualhost>

<VirtualHost>
  ServerName blah2.com
  DocumentRoot /var/www/blah2.com
</Virtualhost>

... etc

I want to take each of these virtual host containers and place them in a separate file(or variable and I can work from there)…

I have been able to take the data in between the strings but not including them. So the output would be …

<VirtualHost>
  ServerName blah2.com
  DocumentRoot /var/www/blah2.com
</Virtualhost>

...iterated through each container and not...
ServerName blah2.com
DocumentRoot /var/www/blah2.com

Please let me know if this is something that can easily be done. Thanks!

  • 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-10T00:33:44+00:00Added an answer on June 10, 2026 at 12:33 am

    A findall regex might work:

    import re
    
    d = """
    <VirtualHost>
      ServerName blah.com
      DocumentRoot /var/www/blah.com
    </Virtualhost>
    <VirtualHost>
      ServerName blah2.com
      DocumentRoot /var/www/blah2.com
    </Virtualhost>
    """
    
    matches = re.findall(r'<VirtualHost>(.*?)</Virtualhost>', d, re.I|re.DOTALL)
    
    #['\n  ServerName blah.com\n  DocumentRoot /var/www/blah.com\n',
    # '\n  ServerName blah2.com\n  DocumentRoot /var/www/blah2.com\n']
    

    Or to include the <VirtualHost> parts:

    matches = re.findall(r'<VirtualHost>.*?</Virtualhost>', d, re.I|re.DOTALL)
    
    #['<VirtualHost>\n  ServerName blah.com\n  DocumentRoot /var/www/blah.com\n</Virtualhost>',
    # '<VirtualHost>\n  ServerName blah2.com\n  DocumentRoot /var/www/blah2.com\n</Virtualhost>']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file I'm trying to open up in python with the following
I am trying to open a text file in python. In the following code:
I have the following typical python project file structure packageA +----subpackage1 +----classa.py +----subpackage2 +----classb.py
I have a text file that I am reading in python . I'm trying
I am really new to Python and I have the following .xml file: <A>
Possible Duplicate: Why avoid while loops? I am trying to learn Python by following
I am trying to accomplish the following logical operation in Python but getting into
Currently I'm trying to write my first Python library and I've encountered the following
I'm having terrible trouble trying to understand python scoping rules. With the following script:
i'm trying making a com dll in python. but i try register to compiled

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.