简体   繁体   中英

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})

to replace 122.22.12.44 with 122.12.12.11 .
In replace section I write \\1\\211 .
So far its not working it just replaces as 122.12.12.4411

Any help I'm using ms word replace function.

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.

Thus, your replacement string should be \\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 .

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