I need to be able to walk through many mxds to replace text strings but able to skip a character place. For example, replace:
'area %d'
with
'area %d - this is some other text'
output:
'area 2'
'area 2 - this is some example text'
'area 3'
'area 3 - this is some example text'
This is what I have so far. It works for replace a specific string but I have not been able to figure out the placeholder variable.
import os
import arcpy
mxd_path = r'C:\Users\username\Desktop\test'
for dirpath, dirnames, filenames in os.walk(mxd_path):
for filename in filenames:
fullPath = os.path.join(dirpath, filename)
basename, extension = os.path.splitext(filename)
if extension.lower() == "*".mxd":
has_data_source = False
mxd = arcpy.mapping.MapDocument(fullPath)
for elm in arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT'):
elm.text = elm.text.replace('area %d',
'area %d - this is some other text')
mxd.save()
del mxd