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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:28:46+00:00 2026-05-19T02:28:46+00:00

I’m trying out regex ( import re ) to extract the info I want

  • 0

I’m trying out regex (import re) to extract the info I want from a log file.

UPDATE: Added the C:\WINDOWS\security folder permissions which broke all of the sample codes.

Say the format of the log is:

C:\:
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    BUILTIN\Users   Allowed:    Read & Execute
    BUILTIN\Users   Allowed:    Special Permissions: 
            Create Folders
    BUILTIN\Users   Allowed:    Special Permissions: 
            Create Files
    \Everyone   Allowed:    Read & Execute
    (No auditing)

C:\WINDOWS\system32:
    BUILTIN\Users   Allowed:    Read & Execute
    BUILTIN\Power Users Allowed:    Modify
    BUILTIN\Power Users Allowed:    Special Permissions: 
            Delete
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    (No auditing)

C:\WINDOWS\system32\config:
    BUILTIN\Users   Allowed:    Read & Execute
    BUILTIN\Power Users Allowed:    Read & Execute
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    (No auditing)

C:\WINDOWS\security:
    BUILTIN\Users   Allowed:    Special Permissions: 
            Traverse Folder
            Read Attributes
            Read Permissions
    BUILTIN\Power Users Allowed:    Special Permissions: 
            Traverse Folder
            Read Attributes
            Read Permissions
    BUILTIN\Administrators  Allowed:    Full Control
    NT AUTHORITY\SYSTEM Allowed:    Full Control
    (No auditing)

And it repeats for a few other directories. How can I split them into paragraphs and then check for lines containing Special Permissions:?

Like this:

  1. Separate the whole string1 into few parts, C:\ and C:\WINDOWS\system32.
  2. Look in each line that contains ‘Special Permissions:’
  3. Display the whole line, e.g.:
    C:\:
    BUILTIN\Users Allowed: Special Permissions: \n\
    Create Folders\n\
    BUILTIN\Users Allowed: Special Permissions: \n\
    Create Files\n\
  4. Repeat for next ‘paragraph’

I was thinking of:
1. Search the whole text file for r"(\w+:\\)(\w+\\?)*:" – return me the path
2. String function or regex to get the rest of the output
3. Remove all the other lines besides the ones with Special Permissions
4. Display, and repeat step 1

But I think it is not efficient.

Can anyone guide me on this? Thanks.


Example output:

C:\:
BUILTIN\Users   Allowed:    Special Permissions:
Create Folders
BUILTIN\Users   Allowed:    Special Permissions:
Create Files

C:\WINDOWS\system32:
BUILTIN\Power Users Allowed:    Special Permissions: 
Delete

C:\WINDOWS\security:
BUILTIN\Users   Allowed:    Special Permissions: 
Traverse Folder
Read Attributes
Read Permissions
BUILTIN\Power Users Allowed:    Special Permissions: 
Traverse Folder
Read Attributes
Read Permissions

C:\WINDOWS\system32\config doesn’t show up as there’s no Special Permission in the lines.


The template I am using:

import re

text = ""

def main():
    f = open('DirectoryPermissions.xls', 'r')
    global text
    for line in f:
        text = text + line
    f.close
    print text

def regex():
    global text
    <insert code here>

if __name__ == '__main__':
    main()
    regex()

  • 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-19T02:28:47+00:00Added an answer on May 19, 2026 at 2:28 am

    Thanks to milkypostman, scoffey, and the rest I came up with the solution:

    def regex():
        global text
        for paragraph in text.split('\n\n'):
            lines = paragraph.split('\n', 1)
            #personal modifier to choose certain output only
            if lines[0].startswith('C:\\:') or lines[0].startswith('C:\\WINDOWS\system32:') or lines[0].startswith('C:\\WINDOWS\\security:'):
                print lines[0]
                iterables = re.finditer(r".*Special Permissions: \n(\s+[a-zA-Z ]+\n)*", lines[1])
                for items in iterables:
                    #cosmetic fix
                    parsedText = re.sub(r"\n$", "", items.group(0))
                    parsedText = re.sub(r"^\s+", "", parsedText)
                    parsedText = re.sub(r"\n\s+", "\n", parsedText)
                    print parsedText
                print
    

    I will still go through all of the posted codes (esp. scoffey’s as I never knew pure string manipulation is that powerful). Thanks for the insight!

    Of course, this will not be the most optimal, but it works for my case. If you have any suggestions, do feel free to post.


    Output:

    C:\Python27>openfile.py
    C:\:
    BUILTIN\Users   Allowed:        Special Permissions:
    Create Folders
    BUILTIN\Users   Allowed:        Special Permissions:
    Create Files
    
    C:\WINDOWS\security:
    BUILTIN\Users   Allowed:        Special Permissions:
    Traverse Folder
    Read Attributes
    Read Permissions
    BUILTIN\Power Users     Allowed:        Special Permissions:
    Traverse Folder
    Read Attributes
    Read Permissions
    
    C:\WINDOWS\system32:
    BUILTIN\Power Users     Allowed:        Special Permissions:
    Delete
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.