I am trying to match a set of strings that follow a certain pattern using re. However, it fails at some point.
Here are the strings that fails
string1= "\".A.B.C.D.E.F.G.H.I.J\""
string2= "\".K.Y.C.A.N.Y.W.H.I.A.W...1.B...1.1.7\""
string3= "\"Testing using quotes func \"quot\".\"":
string4= "A.b.e.f. testing test":
Here is my approach:
"".join(re.findall("\.(\w+)", string1))
Here are my expectations:
"ABCDEFGHIJ"
"KYCANYWHIAW.1B.117"
"Testing using quotes func \"quot\"."
"A.b.e.f. testing test"
It only works for the first string
re.sub(r'(\.)*\.([A-Z0-9])', r'\1\2', string1)?string1andstring2) are missing dots in your expectation? What is your pattern? A.followed by anything not a whitespace-character (matchingstring3likere.sub(r'\.([^.])', r'\g<1>', string1)) or followed by something like[a-zA-Z0-9]as @WiktorStribiżew wrote?