开发者

Match version numbers for graceful fallbacks - with Regex?

My product has version numbers like major.minor.subminor. Various resources get templatized by the version, so that, say, 7.0.1 may define a message, and that may be used thru the 7.X line except for versions 7.2.3 and 7.2.8 which customize the message. 8.0.1 may then change the开发者_运维技巧 message.

I need to get the best matching version of the resources. That would be the last defined version if there was not an exact match, first by subminor, then by minor, then major.

I would think this is a fairly standard practice. Is this kind of a match best done (or even possible) with a regex, and if so, what would the regex be like? Or should I just go ahead and implement this algorithm?


An example: Django uses a list of regexpes to match incoming urls to views.

So a simple list of regexpes, where the first match is the one you want, and then you use it's data.

Your described list should look like this:

/^8/      "Message 4"
/^7.2.8/  "Message 3"
/^7.2.3/  "Message 2"
/^7/      "Message 1"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜