I have something like this:
Othername California (2000) (T) (S) (ok) {state (#2.1)}
Is there a regex code to obtain:
Other
(.+)\s+\(\d+\).+?(?:\(([^)]{2,})\)\s+(?={))?\{.+\(#(\d+\.\d+)\)\}
Name1 Name2 Name3 (2000) {Education (#3.2)} Name1 Name2 Name3 (2000) (ok) {edu (#1.1)} Name1 Name2 (2002) {edu (#1.1)} Name1 Name2 Name3 (2000) (V) {variation (#4.12)} Othername California (2000) (T) (S) (ok) {state (#2.1)}
>>> regex = re.compile("(.+)\s+\(\d+\).+?(?:\(([^)]{2,})\)\s+(?={))?\{.+\(#(\d+\.\d+)\)\}") >>> r = regex.search(string) >>> r <_sre.SRE_Match object at 0x54e2105f36c16a48> >>> regex.match(string) <_sre.SRE_Match object at 0x54e2105f36c169e8> # Run findall >>> regex.findall(string) [ (u'Name1 Name2 Name3' , u'' , u'3.2'), (u'Name1 Name2 Name3' , u'ok', u'1.1'), (u'Name1 Name2' , u'' , u'1.1'), (u'Name1 Name2 Name3' , u'' , u'4.12'), (u'Othername California', u'ok', u'2.1') ]