const regex = /(?(DEFINE)(?'NAMESPACE'\w*::))(?#r)(?(DEFINE)(?'CONSTANT'("(?:[^"\\]|\\.)*")|(\d+\.?\d*f?)))(?#r)(?(DEFINE)(?'VARIABLE'(?P>NAMESPACE)*([A-Za-z_]\w*\.)*[A-Za-z_]\w*))(?#r)(?(DEFINE)(?'OPERAND'(\+|-)*((?P>VARIABLE)|(?P>CONSTANT))))(?#r)(?(DEFINE)(?'EXPRESSION'\s*(?P>OPERAND)\s*(\s*[\*\+-\/]\s*(?P>OPERAND))*))(?#r)(?(DEFINE)(?'ARGUMENTS'(?P>EXPRESSION)(,\s*(?P>EXPRESSION))*))(?#r)(?(DEFINE)(?'FUNCTION_CALL'(?P>VARIABLE)\(\s*(?P>ARGUMENTS)?\s*\)))(?#r)(?P>FUNCTION_CALL)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?(DEFINE)(?\'NAMESPACE\'\\w*::))(?#r)(?(DEFINE)(?\'CONSTANT\'("(?:[^"\\\\]|\\\\.)*")|(\\d+\\.?\\d*f?)))(?#r)(?(DEFINE)(?\'VARIABLE\'(?P>NAMESPACE)*([A-Za-z_]\\w*\\.)*[A-Za-z_]\\w*))(?#r)(?(DEFINE)(?\'OPERAND\'(\\+|-)*((?P>VARIABLE)|(?P>CONSTANT))))(?#r)(?(DEFINE)(?\'EXPRESSION\'\\s*(?P>OPERAND)\\s*(\\s*[\\*\\+-\\\/]\\s*(?P>OPERAND))*))(?#r)(?(DEFINE)(?\'ARGUMENTS\'(?P>EXPRESSION)(,\\s*(?P>EXPRESSION))*))(?#r)(?(DEFINE)(?\'FUNCTION_CALL\'(?P>VARIABLE)\\(\\s*(?P>ARGUMENTS)?\\s*\\)))(?#r)(?P>FUNCTION_CALL)', 'g')
const str = `
[[
::anno::copyright_notice("XXXXX"),
::anno::author("Someone"),
::anno::contributor("")
]]
=
let {
bool tmp0 = false;
material_surface tmp1(
Use_Clearcoat ? ::df::custom_curve_layer(Clearcoat_Center_Level * 0.08f, Clearcoat_Edge_Level, 5.f, 1.f, ::df::microfacet_ggx_smith_bsdf(::math::luminance(::nvidia::core_definitions::blend_colors(color(0.f, 0.f, 0.f), ::base::file_texture(Coat_Roughness_Map, color(0.f, 0.f, 0.f), color(1.f, 1.f, 1.f), ::base::mono_luminance, ::base::texture_coordinate_info(::state::texture_coordinate(0), ::state::texture_tangent_u(0), ::state::texture_tangent_v(0)), float2(0.f, 1.f), float2(0.f, 1.f), ::tex::wrap_repeat, ::tex::wrap_repeat, false).tint, ::base::color_layer_blend, Coat_Roughness_Map_Strength).tint) * ::math::luminance(::nvidia::core_definitions::blend_colors(color(0.f, 0.f, 0.f), ::base::file_texture(Coat_Roughness_Map, color(0.f, 0.f, 0.f), color(1.f, 1.f, 1.f), `;
// 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