From 2721c33a39b5dc03647d7c0a14c6598030aa5d03 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 18 Feb 2026 20:37:28 -0500 Subject: [PATCH] fix: parse equipment number from part names without drawing number Add equipmentOnlyRegex fallback so names like "5028 Prox switch bracket" correctly extract equipment number 5028 even without a drawing number. Handle null DrawingNo in ToString and UI dropdown population. Co-Authored-By: Claude Opus 4.6 --- ExportDXF/DrawingInfo.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ExportDXF/DrawingInfo.cs b/ExportDXF/DrawingInfo.cs index 19a7863..c05083f 100644 --- a/ExportDXF/DrawingInfo.cs +++ b/ExportDXF/DrawingInfo.cs @@ -1,10 +1,11 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace ExportDXF { public class DrawingInfo { private static Regex drawingFormatRegex = new Regex(@"(?[345]\d{3}(-\d+\w{1,2})?)\s?(?[ABEP]\d+(-?(\d+[A-Z]?))?)", RegexOptions.IgnoreCase); + private static Regex equipmentOnlyRegex = new Regex(@"^(?[345]\d{3}(-\d+\w{1,2})?)\b", RegexOptions.IgnoreCase); public string EquipmentNo { get; set; } @@ -14,6 +15,8 @@ namespace ExportDXF public override string ToString() { + if (string.IsNullOrEmpty(DrawingNo)) + return EquipmentNo ?? string.Empty; return $"{EquipmentNo} {DrawingNo}"; } @@ -35,7 +38,21 @@ namespace ExportDXF var match = drawingFormatRegex.Match(input); if (match.Success == false) + { + // Try matching just the equipment number (e.g. "5028 Prox switch bracket") + var eqMatch = equipmentOnlyRegex.Match(input); + if (eqMatch.Success) + { + return new DrawingInfo + { + EquipmentNo = eqMatch.Groups["equipmentNo"].Value, + DrawingNo = null, + Source = input + }; + } + return null; + } var dwg = new DrawingInfo(); @@ -46,4 +63,4 @@ namespace ExportDXF return dwg; } } -} \ No newline at end of file +}