regex - Regexp to normalise (pad with zeroes) IP addresses -


I have a copy of a log file that I want to see / edit.
I do not want to use the textpad to remove stuff and I can enter a regular expression as a search term and in the target field for the captured groups \ 1. \ 2. \ 3 . \ 4 .
Change all IP addresses I want

  [0-9] {1,3} \. [0- 9] {1,3} \. [0- 9] {start each row from 1, 3} \. [0- 9] {1,3}  

to

  [0-9] {3} \. [0- 9] {3} \. [0- 9] {3} \. [0- 9] {3}  

How to do with padded leading zero that at the same time?

Example input:

  10.2.123.4 110.12.23.40 123.123.123.123 1.2.3.4  

Example output

< Pre> 010.002.123.004 110.012.023.040 123.123.123.123 001.002.003.004

See your answer for what works

Thanks for your input < / P>

Not at all, a liner you want, but at least it brings it down into two of your existing Lines instead of 8

After the same formatting used in your answer:

  ^ ([0-9] {1,3}). ([0- 9] {1,3}). ([0- 9] {1,3}). ([0- 9] {1,3}) - & gt; 00 \ 1.00 \ 2.00 \ 3.00 \ 4 ^ 0 * ([0- 9] {3}). 0 * ([0- 9] {3}). 0 * ([0- 9] {3}) .0 * ([0- 9] {3}) - & gt; \ 1. \ 2. \ 3. \ 4  

The way this works is:

  1. It pad all the numbers so that At least 3 numbers in each section there
  2. It draws exactly 3 numbers from each section and any major '0 remaining

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -