我有一个输入文本:
text = '146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622\n197.109.77.178 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] "DELETE /virtual/solutions/target/web+services HTTP/2.0" 203 26554\n156.127.178.177 - [21/Jun/2019:15:45:27 -0700] "DELETE /interactive/transparent/niches/revolutionize HTTP/1.1
output Required :['feest6811','kertzmann3129','-']
output getting :[ ' feest6811', ' kertzmann3129',' ']
下面是使用的代码
user_name = re.findall('(?<=[-])\s[a-zA-Z0-9]*',text)
第二个输出所需:
['POST /incentivize HTTP/1.1','DELETE /virtual/solutions/target/web+services HTTP/2.0','DELETE /interactive/transparent/niches/revolutionize HTTP/1.1']
Output getting :
['POST /incentivize HTTP/1.','DELETE /virtual/solutions/target/web+services HTTP/2.','DELETE /interactive/transparent/niches/revolutionize HTTP/1.']
以下是用于上述第二个输出的代码
request = re.findall('[a-zA-Z]*\s/[a-zA-Z].*[.\+]',text)
正如你所看到的,我在输出 1 和 2 中都遗漏了一些小东西
在输出 1 中,当我们没有数据时,我缺少“-”符号,而在第二个输出中,我无法读取“.”之后的最后一个单词。
任何人都可以建议对代码进行必要的更改吗?
侃侃无极
慕容3067478
一只甜甜圈
相关分类