Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: Matching character set specific number of times

Ok so this is likely a ridiculously stupid question but I can't seem to find a workable answer so please forgive my ignorance if the answer is obvious. All I would like is a Regex which will match a hex value exactly 8 times. So I've tried something like this:

My Regex:

 [0-9a-fA-F]{8}

Sample Input:

 D651000000060D60FADF0DFCE080E020636263633534623231386339

Sample Failing Input (where my given regex matches when I don't want it to):

 ........@%........$dc073bcc-6aa5

Yet for some reason this wont work for me. From what I understand the {8} should match the preceding regex 8 times...yet this doesn't seem to work in either C# or notepad++.

Thanks in advance!

like image 423
Ian Dallas Avatar asked Apr 05 '12 23:04

Ian Dallas


1 Answers

Your question is slightly confusing as to if you want 6 hex characters, 8 times:

([0-9a-fA-F]{6}){8}

Or an 8 digit hex character:

[0-9a-fA-F]{8} or [0-9a-fA-F]{4,8} if you dont want to require 8 characters.

I would recommend testing on:

http://gskinner.com/RegExr/

If these don't get it, can you post a sample of the values you're trying to match (note that if you have these on multiple lines in notepad++ you also need to be looking for the newline characters)

like image 124
DaOgre Avatar answered Nov 03 '22 19:11

DaOgre