I'm working on Python about Regex Data. Here example of my data:
Name: Ahmet Tugra Doger
University: Arel University
Name: Cagatay Yucelen
University: Istanbul Technical University
Okay so, I want to group all name, universities, then change their name in the same time. And for this I use this code:
import re
pattern = re.compile(r'Name: (?<NewName>.*)\nUniversity.*:(?
<NewUniversity>\n*)')
with open('data.txt', 'r') as f:
contents = f.read()
matches = pattern.finditer(contents)
for match in matches:
print(match.group(0))
So after a while I get an error but my expected output result is:
NewName: Ahmet Tugra Doger
NewUniversity: Arel University
NewName: Cagatay Yucelen
NewUniversity: Istanbul Technical University
So, Is there anyway to do it?