Skip to content

Instantly share code, notes, and snippets.

@danmaq
Created February 24, 2017 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmaq/4cffc8d135a235009132def5b53e9226 to your computer and use it in GitHub Desktop.
Save danmaq/4cffc8d135a235009132def5b53e9226 to your computer and use it in GitHub Desktop.
Delete dots appearing after the second time. example: 10.234.156.78 -> 10.23415678
const re = /(\.)(.*)\1+/;
const replace = s => s.match(re) ? replace(s.replace(re, '$1$2')) : s;
const src = '12.345.67.8.90.12345';
document.write('src: ', src);
document.write('<br />');
document.write('dst: ', replace(src));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment