Remove everything except regex match in Vim

前端 未结 4 564
深忆病人
深忆病人 2020-11-29 04:22

My specific case is a text document that contains lots of text and IPv4 addresses. I want to remove everything except for the IP addresses.

I can use :vglobal<

4条回答
  •  不知归路
    2020-11-29 04:44

    Assuming is your regex to match an IP address, I presume you could do something like :

    :%s/.\{-}\(\).*/\1/g
    

    where \1 is the first matched group (the address alone), and .\{-} used for non-greedy matching.

提交回复
热议问题