I am having trouble understanding the regular expressions module in Python. I think what I am trying to do is fairly simple, but I cannot figure it out.
I need to search through some xml files and find this pattern:
'DisplayName="Parcels (10-1-2012)"'
I can parse through the xml and make replacements no problem, the part I cannot figure out is how to do a wild card search to find any instance of "Parcels (some-date-year)". Since the date will vary, I need to find this pattern:
pat = '"Parcels (*-*-*)"'
and I want to replace it with today's date which I can do with the time module. I copied out a line of one of the 80 or so xml docs where I would need to find the pattern.
According to the help for the re.search() function, it seems I can just put in a pattern, then the string I wish to search through. However, I am getting errors.
Help on function search in module re:
search(pattern, string, flags=0) Scan through string looking for a match to the pattern, returning a match object, or None if no match was found.
Here is my little test snippet:
import re
pat = '"Parcels (*-*-*)"'
t= ' <Layer DisplayName="Parcels (7-1-2010)" FeatureDescription="Owner Name: {OWNER_NAME}<br/>Property Address: {PROP_ADDR}<br/>Tax Name: {TAX_NAME}<br/>Tax Address 1: {TAX_ADD_L1}<br/>Tax Address 2: {TAX_ADD_L2}<br/>Land Use: {USE1_DESC}<br/><a href="http://www16.co.hennepin.mn.us/pins/pidresult.jsp?pid={PID_NO}">View Property Information</a><br/><br/><br/>" FeatureLabel="Parcel ID: {PID_NO}" IconUri="{RestVirtualDirectoryUrl}/Images/Parcel.png" Identifiable="true" IncludeInLayerList="true" IncludeInLegend="true" Name="Parcels" Searchable="true" ShowMapTips="true" UnconfiguredFieldsSearchable="true" UnconfiguredFieldsVisible="true" Visible="true">'
match = re.search(pat, t)
print match
Most of the line is junk I don't need to worry about. I just need to see how I can find that date in the line so I can use just that piece in the replace() function. Does anyone know how I could find these dates? There may be other dates in the xml somewhere, but I don't need to replace these; just where it says "Parcels (some-date-year)". I appreciate any help! Thanks!