简体   繁体   English

正则表达式以ms字替换最后一个八位字节?

[英]Regex in ms word to replace last octet?

I'm using this 我正在用这个

([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})(.[0-9]{1,3}) ([0-9] {1,3}。[0-9] {1,3}。[0-9] {1,3})([0-9] {1,3})

to replace 122.22.12.44 with 122.12.12.11 . 122.22.12.44替换为122.12.12.11
In replace section I write \\1\\211 . 在替换部分中,我写\\1\\211
So far its not working it just replaces as 122.12.12.4411 到目前为止,它不起作用,它只是替换为122.12.12.4411

Any help I'm using ms word replace function. 我正在使用ms word替换功能的任何帮助。

Adding as answer. 添加为答案。

When you are using regex 使用正则表达式时

([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})(.[0-9]{1,3})

to match, the first bracked matches the first three octets & the seconds bracket matches the last octet. 为了匹配,第一个括号匹配前三个八位字节,秒括号匹配最后一个八位字节。

Since you want to replace the last octet, you should keep the first 3 octets as they are (use \\1 ) & append the replacement octet after that. 由于您要替换最后一个八位位组,因此应将前三个八位位组保持原样(使用\\1 ),并在此后附加替换八位位组。

Thus, your replacement string should be \\1.11 . 因此,您的替换字符串应为\\1.11

Currently is it set to \\1\\211 Thus it match all the four octets & appends 44 after it, giving you result as 122.12.12.4411 . 当前它设置为\\1\\211因此它匹配所有四个八位字节并在其后附加44,结果为122.12.12.4411

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

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