我想转换一下:
LIVE | 139.59.101.223:1080 | 0.8 | Unknow | Unknow |
LIVE | 139.59.61.29:1080 | 0.77 | Unknow | Unknow |
LIVE | 91.122.46.56:9050 | 0.8 | Unknow | Unknow |
LIVE | 138.68.232.41:1080 | 0.23 | Unknow | Unknow |
到此:
139.59.101.223:1080
139.59.61.29:1080
91.122.46.56:9050
138.68.232.41:1080
我该怎么做?
我想在notepad ++中使用
答案 0 :(得分:0)
有点严格的匹配模式:
pattern = (r'LIVE \| '
r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5} \| '
r'\d+\.?\d* \| '
r'Unknow \| Unknow \|')
matches = [re.match(pattern, line)[1] for line in lines]
答案 1 :(得分:0)
不使用正则表达式的解决方案......
_, ip, *_ = line.split('|')
ip = ip.strip()
在示例......
>>> line = "LIVE | 139.59.101.223:1080 | 0.8 | Unknow | Unknow |"
>>> _, ip, *_ = line.split('|')
>>> ip = ip.strip()
>>> print(ip)
139.59.101.223:1080
答案 2 :(得分:0)
按from io import BytesIO
from zipfile import ZipFile
MYCHUNKSIZE = 10
archive_file = r"test_resources\0000232514_bom.zip"
src_file = r"0000232514_bom.xls"
no_of_chunks_to_read = 10
with ZipFile(archive_file,'r') as zf:
with zf.open(src_file) as src_f:
while no_of_chunks_to_read > 0:
chunk_str = src_f.read(MYCHUNKSIZE)
chunk_stream = BytesIO(chunk_str)
chunk_bytes = chunk_stream.read()
print type(chunk_bytes), len(chunk_bytes), chunk_bytes
if len(chunk_str) < MYCHUNKSIZE:
# End of file
break
no_of_chunks_to_read -= 1
调出替换对话框,下面的正则表达式只捕获IP号文本并丢弃其他内容
查找:ctrl + h
替换为:.*?(\d+\.\d+\.\d+\.\d+:\d+).*
选择正则表达式单选按钮,然后替换所有
答案 3 :(得分:0)
你能做的就是使用正则表达式
LIVE \| (.+?) \|.*
用于捕获您在组中查找的数据,并将其替换为第1组\1
<强>解释强>
LIVE \|
(.+?)
(这将包含您的数据).*
如果你有这个字符串:
LIVE | 139.59.101.223:1080 | 0.8 | Unknow | Unknow |
第1组将包含139.59.101.223:1080