lundi 27 juin 2016

specific Regular expression search python

This is my first post. I always come to this forum looking for an answer when it comes to code.

I have been fighting with understanding regular expressions in Python, but it is kind of hard.

I have text that looks like this:

Name:   Clash1
Distance:   -1.341m
Image Location: Test 1_navis_filescd000001.jpg
HardStatus: New
Clash Point:    3.884m, -2.474m, 2.659m
Date Created:   2016/6/2422:45:09

Item 1
GUID:   6efaec51-b699-4d5a-b947-505a69c31d52
Path:   File ->Colisiones_v2015.dwfx ->Segment ->Pipes (1) ->Pipe Types (1) ->Default (1) ->Pipe Types [2463] ->Shell
Item Name:  Pipe Types [2463]
Item Type:  Shell

Item 2
GUID:   6efaec51-b699-4d5a-b947-505a69c31dea
Path:   File ->Colisiones_v2015.dwfx ->Segment ->Walls (4) ->Basic Wall (4) ->Wall 1 (4) ->Basic Wall [2343] ->Shell
Item Name:  Basic Wall [2343]
Item Type:  Shell

------------------


Name:   Clash2
Distance:   -1.341m
Image Location: Test 1_navis_filescd000002.jpg
HardStatus: New
Clash Point:    3.884m, 3.533m, 2.659m
Date Created:   2016/6/2422:45:09

Item 1
GUID:   6efaec51-b699-4d5a-b947-505a69c31d52
Path:   File ->Colisiones_v2015.dwfx ->Segment ->Pipes (1) ->Pipe Types (1) ->Default (1) ->Pipe Types [2463] ->Shell
Item Name:  Pipe Types [2463]
Item Type:  Shell

Item 2
GUID:   6efaec51-b699-4d5a-b947-505a69c31de8
Path:   File ->Colisiones_v2015.dwfx ->Segment ->Walls (4) ->Basic Wall (4) ->Wall 1 (4) ->Basic Wall [2341] ->Shell
Item Name:  Basic Wall [2341]
Item Type:  Shell

------------------

What I need to do is to create a list that extracts for every chunk of text (separated by the -------------------------------) the following things as a string: the clash name and the clash point.

For example: Clash 1 3.884, 3.533, 2.659

I am really new to Python, and really do not have much understanding about regular expressions.

Can anyone give me some clues about using regex to extract this values from the text?

I did something like this:

exp = r'(?<=Clash Points)(?<=Points)([0-9]*)'
match = re.findall(exp, html)

if match:
    OUT.append(match)
else:
    OUT = 'fail'

but I know I am far from my goal.

Aucun commentaire:

Enregistrer un commentaire