Python Regular Expression to Match the Whole line

前端 未结 3 1561
天命终不由人
天命终不由人 2021-01-13 12:21

I\'m new to scripting and have been reading about how to use regular expressions.

I want to fetch the complete line matching a pattern.

my ouptut is:

3条回答
  •  情深已故
    2021-01-13 12:47

    Try

    cmd = re.search('^.*\d*% packet loss.*$', ping_result[int(i)], re.M|re.I)
    print cmd.group()
    

    '^' and '$' match the start and end of a line, respectively. You also don't need the parentheses unless you want to select the packet loss separately.

提交回复
热议问题