Mr. Toast Mr. Toast - 8 months ago 24
C# Question

Specific regex in C# .NET

I need to build a regular expression which should apply for the following:

(Valid for 1 - 4 Blocks (seperated with "/") which contain exactly 4 characters that are HEX numbers)

Valid example 1: 3F00 / FA41 / FA12 / B12F
Valid example 2: 4F0T
Valid example 3: FFFF / FF21

Invalid example 1: 34BF /
Invalid example 2: 45FB2
Invalid example 3: 4B5S / BD45 BA56
Invalid example 4: FF02/B200
...


I just can't figure it out. Here's what I have for now:

1: ([0-9A-F]{4})( \/ \1){1,3}|[0-9A-F]{4}
2: [0-9A-F]{4} \/ [0-9A-F]{4} \/ [0-9A-F]{4} \/ [0-9A-F]{4}|[0-9A-F]{4} \/ [0-9A-F]{4} \/ [0-9A-F]{4}|[0-9A-F]{4} \/ [0-9A-F]{4}|[0-9A-F]{4}


Second pretty ugly and both not working!

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download