const regex = /^(
( # define some frequently used capture groups
(?!x)x # always false ("match only if there is no 'x' ahead and there is 'x' ahead")
(?<name>[^_]+) # group "name", name of the program/library
(?<os>windows|linux|osx|android) # group "os", operating systems
(?<arch>x86-64|x86|arm64|armhf|armel|multiarch) # group"arch", architectures
(?<buildtype>release|debug) # group"buildtype", build types
(?<linking>shared|static|mixed) # group "linking", library linking/build types
)
|
( # regular executable builds
(?!lib)\g<name>_build_\g<os>_\g<arch>_\g<buildtype>
)
|
( # library builds
lib\g<name>_build_\g<os>_\g<arch>_\g<linking>_\g<buildtype>
)
|
( # syncing source code of a project from git or something else
\g<name>_src
)
|
( # static code analizer
\g<name>_analyze_(cppcheck|scan-build)
)
|
( # package builds
\g<name>_pkg_\g<os>_
(
((?<=linux_) # if there is "linux_" before here
# then match
(deb|rpm)_
(shared|static)_
(
((?<=deb_shared_) # if there is "deb_shared_" before here
# then match
(wheezy|jessie|stretch|sid|trusty|xenial|yakkety)_
)
|
((?<!deb_shared_) # if there is no "deb_shared_", don't match anything
)
)
)
|
((?<!linux_) # if there is no "linux_", don't match anything
)
)
\g<arch>_(stable|nightly)_\g<buildtype>
)
)$/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(
( # define some frequently used capture groups
(?!x)x # always false ("match only if there is no \'x\' ahead and there is \'x\' ahead")
(?<name>[^_]+) # group "name", name of the program\/library
(?<os>windows|linux|osx|android) # group "os", operating systems
(?<arch>x86-64|x86|arm64|armhf|armel|multiarch) # group"arch", architectures
(?<buildtype>release|debug) # group"buildtype", build types
(?<linking>shared|static|mixed) # group "linking", library linking\/build types
)
|
( # regular executable builds
(?!lib)\\g<name>_build_\\g<os>_\\g<arch>_\\g<buildtype>
)
|
( # library builds
lib\\g<name>_build_\\g<os>_\\g<arch>_\\g<linking>_\\g<buildtype>
)
|
( # syncing source code of a project from git or something else
\\g<name>_src
)
|
( # static code analizer
\\g<name>_analyze_(cppcheck|scan-build)
)
|
( # package builds
\\g<name>_pkg_\\g<os>_
(
((?<=linux_) # if there is "linux_" before here
# then match
(deb|rpm)_
(shared|static)_
(
((?<=deb_shared_) # if there is "deb_shared_" before here
# then match
(wheezy|jessie|stretch|sid|trusty|xenial|yakkety)_
)
|
((?<!deb_shared_) # if there is no "deb_shared_", don\'t match anything
)
)
)
|
((?<!linux_) # if there is no "linux_", don\'t match anything
)
)
\\g<arch>_(stable|nightly)_\\g<buildtype>
)
)$', '')
const str = `qtox_pkg_linux_deb_shared_jessie_x86_stable_release`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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