(moving to Category:Advanced Regex) |
(Move categories to tip template) |
||
Line 9: | Line 9: | ||
|version=6.0 |
|version=6.0 |
||
|rating=41/17 |
|rating=41/17 |
||
⚫ | |||
+ | |category2= |
||
}} |
}} |
||
If you edit files which contain IP addresses and would like to have them marked in special color, you can use the following code in your vimrc: |
If you edit files which contain IP addresses and would like to have them marked in special color, you can use the following code in your vimrc: |
||
Line 33: | Line 35: | ||
---- |
---- |
||
⚫ |
Revision as of 08:59, 25 April 2008
Tip 1073 Printable Monobook Previous Next
created December 9, 2005 · complexity basic · author Matous Jan Fialka · version 6.0
If you edit files which contain IP addresses and would like to have them marked in special color, you can use the following code in your vimrc:
syn match ipaddr /\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)/ hi link ipaddr Identifier
This will highlight them the same way identifiers are highlighted in your code.
The tip uses the classical regexp for matching IP addresses:
((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
If you just want to match a simple IP address that is probably valid, then something like this would be simpler:
\d\{1,3}\%(\.\d\{1,3}\)\{3}
However, this will also match something like 999.999.999.999, which is obviously not valid.