Regex help - word matching except MD5 hashes

I cannot find a regular expression that will capture every word except MD5 hashes. - I use [a-zA-Z0-9]+ to match every word. How to increase the size so that it ignores what I think is like [a-fA-F0-9]{32} , which will correspond to MD5 hashes. My question is about Regex.

 8e85d8b3be426bc8d370facdb0ad3ad0 string stringString 63994b32affec18c2a428cdfcb0e2823 stringSTRINGSTING333 34563994b32dddddddaffec18c2a stringSTRINGSTINGsrting 

Thanks for any help. :)

+4
source share
3 answers

This view is usually done with a negative look:

 /\b(?![0-9a-f]{32}\b)[A-Za-z0-9]+\b/ 

At the beginning of each word (?![0-9a-fA-F]{32}\b) tries to match exactly 32 hexadecimal digits, followed by the word boundary. If this succeeds, the regular expression fails.

+2
source

The following works great for me:

 /^[a-f0-9]{8}(-)[a-f0-9]{4}(-)[a-f0-9]{4}(-)[a-f0-9]{4}(-)[a-f0-9]{12}$/i 
+1
source

as already said, just take all the words that don't match the MD5 hashes.
(firstly you need to split the line)

 var s = "8e85d8b3be426bc8d370facdb0ad3ad0\nstring\nstringString\n63994b32affec18c2a428cdfcb0e2823\nstringSTRINGSTING333\n34563994b32dddddddaffec18c2a\nstringSTRINGSTINGsrting"; words = []; words_all = s.split(/\s+/); for (i in words_all) { word = words_all[i]; if (! word.match(/^[a-fA-F0-9]{32}$/)) { words.push(word) } } // words = ["string", "stringString", "stringSTRINGSTING333", "34563994b32dddddddaffec18c2a", "stringSTRINGSTINGsrting"] 

(assuming that according to your source code you want to use javascript)

0
source

All Articles