regex101: sources.list line match

Match a single line inside of an apt sources.list file and return content in named groups.

This regex should take into account many possible variations of a sources.list entry, but by far not all of them.

What it does:

  • recognize most of the protocols supported by apt
  • require the URI to begin with a domain of a remote machine, when using those protocols, which require this
  • support for optional arguments like options and arbitrarily many components
  • case sensitivity for the possibility of the suite containing an exact path, in which case the line mustn’t contain any components

That it does not:

  • support spaces inside the URI, which APT also doesn’t as far , as I know
  • support uncommon characters in URI and components
  • usage of IP addresses instead of domains
  • split list of options or components into separate groups
  • validity check for options

Read more here: Source link