Chen Chen - 2 years ago 67
Python Question

'(match_start1)...(match_start2)...(match_end)' find the shortest string match

I've read over this post but the answer there doesn't work for my case.

I was looking for pattern

'\D\d{2,5}?.+?CA.??[ \-\.\_]*(?:\d{5})?',
the string is '6785 56767at435 hjfioej st. CA. 94827ifojwnf 93842'

't435 hjfioej st. CA. 94827'
' 56767at435 hjfioej st. CA. 94827'
should match, but the procedure given in the above post is not giving the minimum match.

Please help.

Answer Source
re.findall('(?=(\D\d{2,5}?.+?CA.?[ -._]*(?:\d{5})?))','6785 56767at435 hjfioej st. CA. 94827ifojwnf 93842')

So this will do the trick, then output the one of the minimum length.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download