javascript - A regex for an application version -


I want to type regex to match an application version in JavaScript using the pattern:

  (0-255). (0-255) [. (0-65535). (0-65535)]  

Here is my result:

  ^ (?: (\ D +) \.) {?} (?: (\ D +) \.) {1} (?: (\ D +) \.)? (\ D +)? $  

But this allows the string with the dot at the end (like '111.222.333.') And does not limit the number of digits. Any help?

Update

This pattern is better:

  (0-255). (0-255) [. (0-65535)]. (0-65535)]  

The result is:

  ^ (?: [0- 9] {1, 2} | 1 [0- 3] | 2 [0-4] [0-9] | 25 [0-5]) (? [.] ?: ((:: [0-9] {1,4} | [1-5] [0-9 ] {4} | 6 [0-4] [0-9] {3} | 65 [0-4] [0-9] {2} | 655 [0- 2] [0-9] | 6553 [0 -5])) {1}) (: (: [] (??.? [0-9] {1,4} | [1-5] [0-9] {4} | 6 [0-4] ] [0-9] {3} | 65 [0-4] [0-9] {2} | 655 [0-2] [0-9] | 6553 [0-5])) {1})? $  

I think the best solution for you is . and check each part:

  function isInbound (value, minimum, maximum) {return! IsNaN (value) & amp; Amp; Price & gt; = Minutes & amp; Amp; Value & lt; = Max; } Function CheckVision (version) {var parts = version.split ("."); Switch (parts.length) {case 4: for case 3: (var i = 2; i & lt; parts.length; i ++) {if (!! Is inbound (part (part [i], 10), 0, 65535)) {Description is false; }} // fallthrough case 2: for (var i = 0; i & lt; 2; i ++) {If (!! Inbounds (parts (parts [i], 10), 0, 255)) {return false ; }         }         break; Default: Return false; } Back true; } Console.log (checkVersion ("foo")); // false console.log (CzechWarsian ("foo.bar")); // false console.log (CzechWarsian ("foo.bar.foo")); // false console.log (checkVersion ("foo.bar.foo.bar")); // false console.log (checkwarson ("256"); // false console.log (checkwarson ("256.256")); // false console.log (checkwarson ("256.256.65536")); // false console.log (checkwarson ("256.256.65536.65536")); // false console.log (checkwarsen ("42")); // false console.log (checkwarson ("42.42")); // true console.log (checkwarson ("42.42.42")); // true console.log (checkwarson ("42.42.42.42")); Regex is probably not the way to go, because it does not handle the boundaries very well. For the only challenge, here is a must for you (many ;) ): 

  ^ (?: [ 0-9] {1,2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5]) ([.]: [0- 9] { 1,2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5]) (?.? (?: [] ([0-9] {1 , 4} | [1-5] [0-9] {4} | 6 [0-4] [0-9] {3} | 65 [0-4] [0-9] {2} | 655 [ 0-2] [0-9] | 6553 [0-5]) {1,2}) $  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -