See https://regex101.com/r/OX1W3b/2/ for one example...
1. DIMENSIONS: | ORIGIN: | Position corrected and IL (0) was changed based on RPS: 3482 -230
2. DIMENSIONS: 2 x 1350 RCP | ORIGIN: PCD13180 | Position corrected and IL (0) was changed based on RPS: 1390 -20800/1350RCP
3. DIMENSIONS: 3 x 375 RCP | ORIGIN:
4. DIMENSIONS: | ORIGIN:
5. Review attribution | DIMENSIONS: | ORIGIN:
1. Position corrected and IL (0) was changed based on RPS: 3482 -230
2. DIMENSIONS: 2 x 1350 RCP | ORIGIN: PCD13180 | Position corrected and IL (0) was changed based on RPS: 1390 -20800/1350RCP
3. DIMENSIONS: 3 x 375 RCP
4.
5. Review attribution
Here's the current code - see line 10 and 33 for the regex based commands.
#Use in QGIS 3 python console
#Search and replace text in all fields of all layers
#Also allows regex use
import re
#Based on https://gis.stackexchange.com/questions/317855/search-and-replace-text-in-all-fields-in-qgis-3
#set text to search for and replace with.
searchText = "DIM"
regexText = ".*(DIMENSIONS: \|)"
replaceText = ""
#run on all layers
layers = QgsProject.instance().mapLayers()
for layer_id, layer in layers.items():
i=1
print("Layer: %s" % (layer.name()))
# get data provider
dpr = layer.dataProvider()
for field in layer.fields():
fieldName=field.name()
for feature in layer.getFeatures():
inText = str(feature[fieldName])
# get field index
fieldIndex = layer.fields().indexFromName(fieldName)
#print ("Checking %s" % (inText))
if searchText in inText:
# change inText
print ("%s . REPLACED: %s in %s with %s in column: %s" % (i, searchText, inText, replaceText, fieldName))
#outText = inText.replace(searchText, replaceText)
outText = re.sub(fieldName, regexText, replaceText)
i+=1
# save changes
dpr.changeAttributeValues({feature.id(): {fieldIndex: outText}})
print ("Completed")