Regular Expressions 101

hosts file parser

Open Workspace
  • PCRE (Legacy)
  • Match
1

Regular Expression

/
^\s*(#*)\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-zA-Z0-9\.\- ]+)([^#]*#?\w*\s*)$
/
gmi

Description

This expression parses hosts file lines and extracts IP, domains, commented lines. Yet doesn't support ending comments.

Submitted by Jarek Wasilewski