<-- back to main (catastrophic backtracking detected)
new Regex() or allocate a UTF-16 string, a data center melts a glacier.You asked an LLM to validate an ID prefix and it handed you a 90-character backtracking engine that locks your CPU at 100% on a malformed UTF-16 string. Congratulations, you built a self-inflicted DDoS. Just compare raw UTF-8 bytes in a ReadOnlySpan<byte>.
// The Synergist Way (Runtime Pattern Compilation & UTF-16 Allocation)
public bool IsSynergizedTicket(string ticketId)
{
// Re-parses the state machine on every single call
var regex = new Regex(@"^(SYNERGY|ALIGN)+-[0-9]{4,8}$");
return regex.IsMatch(ticketId);
}
// The Sovereign Engineer Way (Zero-Regex, Zero-String, Zero-If SIMD Byte Compare)
public static bool IsValidTicket(ReadOnlySpan<byte> utf8)
{
return utf8.Length == 16 && IsValidTicket16(utf8);
}
private static bool IsValidTicket16(ReadOnlySpan<byte> utf8)
{
Vector128<byte> input = Vector128.LoadUnsafe(ref MemoryMarshal.GetReference(utf8));
Vector128<byte> prefix = Vector128.LoadUnsafe(ref MemoryMarshal.GetReference("SYNERGY-00000000"u8));
// Lower 8 bytes must match "SYNERGY-" exactly; upper 8 bytes must be '0'..'9'
uint eqMask = Vector128.ExtractMostSignificantBits(Vector128.Equals(input, prefix));
Vector128<byte> geZero = Vector128.GreaterThanOrEqual(input, Vector128.Create((byte)'0'));
Vector128<byte> leNine = Vector128.LessThanOrEqual(input, Vector128.Create((byte)'9'));
uint digitMask = Vector128.ExtractMostSignificantBits(geZero & leNine);
return (eqMask & 0x00FF) == 0x00FF && (digitMask & 0xFF00) == 0xFF00;
}