You need to replace the id from content2 (this is TU7D2IH8P2D001 ) with the id from content1 ( TYA1G2C9HMD001 ) only if the rest of the expression is the same. That is, as a result, the zero elements of the two arrays should become equal, and the first ones should remain as they are. I have the following code:
import re content1 = ['MY SECRET CODE IS TYA1G2C9HMD001(\n YEAH IT IS EASY!\n', "HIS SECRET CODE IS TU2Z3D43D4D002(\n THIS IS DIFFERENT PART\n"] content2 = ['MY SECRET CODE IS TU7D2IH8P2D001(\n YEAH IT IS EASY!\n', "HIS SECRET CODE IS TU2A3C83D4D002(\n THIS IS DIFFERENT PARTS\n"] pattern = re.compile("^(.)*T[A-Z0-9]{10}[0-9]{3}[(](.)*$") for c1, c2 in zip(content1, content2): # как-то сравнить id из c1 и с2 здесь I understand that this needs to be done somehow with re.sub, but I don’t understand how to add a check for equality of the rest of the string. The python version is 2.7. Thank you in advance!
idin one list item? - MaxU