简体   繁体   中英

replace IP address in file

I want to replace IP addresses in a file. 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. The IP to be replaced may have either ; or < after the IP. Using .\\d{1,3}\\D in a search and replace I end up losing the character after the IP.

Try this:

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

if you want to match IP's with 1-3 digits at the end.

try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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