python - regex parsing log
Question: i have the following log line i want to parse

    
    
    <log pos_start="40652288" end_position="40689664" log_type="1" length="37376" block_id="4024" block_position="18"/>
    

i am using python regex, this is what i did so far

    
    
    regexParse = re.match(".*pos_start=(\d+).*end_position=(\d+).*log_type=(\d+).*length=(\d+).*block_id=(\d+).*block_position=(\d+).*",StatelogLine)
    start_position = regexParse.group(1)
    end_position = regexParse.group(2)
    

i am getting the following error

    
    
    AttributeError: 'NoneType' object has no attribute 'group'
    

anyone has any ideas what is the problem


Answer: Pretty simple: your [regex does not match your
string](https://regex101.com/r/aW9aR7/1) **because of the not specified double
quotes** , that is. If you add them, [your regex
works](https://regex101.com/r/aW9aR7/2).  
As a side node, the dot-star soup (`.*`) is very inefficient. Why not use a
parser instead?

Consider the following code with `BeautifulSoup`:

    
    
    from bs4 import BeautifulSoup
    string = """<log pos_start="40652288" end_position="40689664" log_type="1" length="37376" block_id="4024" block_position="18"/>"""
    xml = BeautifulSoup(string)
    print xml.log["pos_start"]
    # 40652288
    

You can access your element like an array afterwards, no druidic regex needed.
Have a look at [their homepage and
documentation](https://www.crummy.com/software/BeautifulSoup/).

