简体   繁体   English

替换文件中的IP地址

[英]replace IP address in file

I want to replace IP addresses in a file. 我想替换文件中的IP地址。 Example file 示例文件

255.255.255.22<
255.255.255.222<
255.255.255.22;
255.255.255.222;

The files are config files. 这些文件是配置文件。 Say, I need to replace 255.255.255.22 but not 255.255.255.222. 说,我需要替换255.255.255.22而不是255.255.255.222。 The IP to be replaced may have either ; 要更换的IP可能有; or < after the IP. <在IP之后。 Using .\\d{1,3}\\D in a search and replace I end up losing the character after the IP. 在搜索和替换中使用.\\d{1,3}\\D我最终会丢失IP后的字符。

Try this: 尝试这个:

"(\d{1,3}\\.){3}(\d{2})(?=[<;])"

if you want to match IP's with 1-3 digits at the end. 如果你想匹配最后的1-3位数的IP。

try this: 尝试这个:

"(\\d{1,3}\\\\.){3}(\\d{1,3})(?=[<;])"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM