Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created October 4, 2023 07:49
Show Gist options
  • Save guitarrapc/52439239e19634c9e54fa243158ace60 to your computer and use it in GitHub Desktop.
Save guitarrapc/52439239e19634c9e54fa243158ace60 to your computer and use it in GitHub Desktop.
Regex match example with some Unity Headless log.
void Main()
{
var messages = new[] {
"Invalid VFX Particle System. It is skipped.",
"WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?",
"WARNING: Shader Did you use #pragma only_renderers and omit this platform?",
"ERROR: Shader Sniper/InvisibleShadowCasterUniversalRP shader is not supported on this GPU (none of subshaders/fallbacks are suitable)",
"ERROR: Shader Hidden/Universal Render Pipeline/Foobar shader is not supported on this GPU (none of subshaders/fallbacks are suitable)",
"WARNING: Shader Unsupported: 'SineVFX/FooEffects/SG/DissolveParticleFlip' - All subshaders removed",
};
var regexes = new[] {
new Regex("^Invalid\\s+VFX\\s+Particle\\s+System\\.", RegexOptions.Compiled),
new Regex("^\\w+:\\s+Shader\\s+.*", RegexOptions.Compiled),
};
foreach (var message in messages)
{
var matched = false;
foreach (var regex in regexes)
{
matched = regex.IsMatch(message);
if (matched)
{
$"MATCHED: {message} <- `{regex.ToString()}`".Dump();
break;
}
}
if (!matched)
{
$"FAILED: {message}".Dump();
}
}
}
// MATCHED: Invalid VFX Particle System. It is skipped. <- `^Invalid\s+VFX\s+Particle\s+System\.`
// MATCHED: WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off? <- `^\w+:\s+Shader\s+.*`
// MATCHED: WARNING: Shader Did you use #pragma only_renderers and omit this platform? <- `^\w+:\s+Shader\s+.*`
// MATCHED: ERROR: Shader Sniper/InvisibleShadowCasterUniversalRP shader is not supported on this GPU (none of subshaders/fallbacks are suitable) <- `^\w+:\s+Shader\s+.*`
// MATCHED: ERROR: Shader Hidden/Universal Render Pipeline/Foobar shader is not supported on this GPU (none of subshaders/fallbacks are suitable) <- `^\w+:\s+Shader\s+.*`
// MATCHED: WARNING: Shader Unsupported: 'SineVFX/FooEffects/SG/DissolveParticleFlip' - All subshaders removed <- `^\w+:\s+Shader\s+.*`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment