English 中文(简体)
Regex帮助-匹配MD5哈希之外的单词
原标题:Regex help - match words besides MD5 hashes
  • 时间:2010-10-16 22:55:16
  •  标签:
  • regex

我想不出一个正则表达式来抓取MD5哈希之外的所有单词。-我使用[a-zA-Z0-9]+来匹配每个单词。我如何增强它,使其忽略我认为与MD5哈希匹配的[a-fA-F0-9]{32}之类的东西。我的问题是关于雷格斯的。

8e85d8b3be426bc8d370facdb0ad3ad0
string
stringString
63994b32affec18c2a428cdfcb0e2823
stringSTRINGSTING333
34563994b32dddddddaffec18c2a
stringSTRINGSTINGsrting

谢谢你的帮助。:)

问题回答

这种事情通常是在消极展望的情况下完成的:

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

在每个单词的开头,(?![0-9a-fA-F]{32})试图精确匹配后跟单词边界的32个十六进制数字。如果成功,正则表达式将失败。

以下对我来说很好:

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

as already said, just grab all words which do not match to be MD5 hashes.
(first, you have to split the string)

var s = "8e85d8b3be426bc8d370facdb0ad3ad0
string
stringString
63994b32affec18c2a428cdfcb0e2823
stringSTRINGSTING333
34563994b32dddddddaffec18c2a
stringSTRINGSTINGsrting";

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"]

(假设根据您的原始代码,您希望使用javascript)





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签