I have strings like:
q.0.0.0.1-1111, q.0.0.0.1.tt_0-1111, tes-00000000-1111
I need cut this strings and get:
q.0.0.0-1111, q.0.0.0-1111, tes-1111
How i can get it with help of regexp?
>Solution :
If searching for specific one-pass regexp solution I’d suggest the following substitution:
import re
s = 'q.0.0.0.1-1111, q.0.0.0.1.tt_0-1111, tes-00000000-1111'
s = re.sub(r'(?<=[^-\s]{7})[^-]+(?=-)|(?<=-)[^-\s]+-', '', s)
print(s)
q.0.0.0-1111, q.0.0.0-1111, tes-1111