const regex = /^((\s+|)(\/\/|#)|$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^((\\s+|)(\\\/\\\/|#)|$)', 'gm')
const str = `##################################################################
#### /etc/apt/apt.conf.d/50unattended-upgrades ###
// Automatically upgrade packages from these (origin:archive) pairs
//
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
Unattended-Upgrade::Allowed-Origins {
"\${distro_id}:\${distro_codename}";
"\${distro_id}:\${distro_codename}-security";
// Extended Security Maintenance; doesn't necessarily exist for
// every release and this system may not have it installed, but if
// available, the policy for updates is such that unattended-upgrades
// should also install from here by default.
"\${distro_id}ESMApps:\${distro_codename}-apps-security";
"\${distro_id}ESM:\${distro_codename}-infra-security";
// "\${distro_id}:\${distro_codename}-updates";
// "\${distro_id}:\${distro_codename}-proposed";
// "\${distro_id}:\${distro_codename}-backports";
};
// Python regular expressions, matching packages to exclude from upgrading
Unattended-Upgrade::Package-Blacklist {
// The following matches all packages starting with linux-
// "linux-";
// Use \$ to explicitely define the end of a package name. Without
// the \$, "libc6" would match all of them.
// "libc6\$";
// "libc6-dev\$";
// "libc6-i686\$";
// Special characters need escaping
// "libstdc\\+\\+6\$";
// The following matches packages like xen-system-amd64, xen-utils-4.1,
// xenstore-utils and libxenstore3.0
// "(lib)?xen(store)?";
// For more information about Python regular expressions, see
// https://docs.python.org/3/howto/regex.html
};
// This option controls whether the development release of Ubuntu will be
// upgraded automatically. Valid values are "true", "false", and "auto".
Unattended-Upgrade::DevRelease "auto";
##################################################################
#### /etc/cron.weekly/man-db ###
#!/bin/sh
#
# man-db cron weekly
set -e
if [ -d /run/systemd/system ]; then
# Skip in favour of systemd timer.
exit 0
fi
iosched_idle=
# Don't try to change I/O priority in a vserver or OpenVZ.
if ! egrep -q '(envID|VxID):.*[1-9]' /proc/self/status && \\
([ ! -d /proc/vz ] || [ -d /proc/bc ]); then
iosched_idle='--iosched idle'
fi
if ! [ -d /var/cache/man ]; then
# Recover from deletion, per FHS.
install -d -o man -g man -m 0755 /var/cache/man
fi
# regenerate man database
if [ -x /usr/bin/mandb ]; then
# --pidfile /dev/null so it always starts; mandb isn't really a daemon,
# but we want to start it like one.
start-stop-daemon --start --pidfile /dev/null \\
--startas /usr/bin/mandb --oknodo --chuid man \\
\$iosched_idle \\
-- --quiet
fi
exit 0`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions