split version using Regexp
I have a version like this “5.3.08.01”, I want to split this version string into four so that each digit get assigned to variables, means it should be like this:
A= 5
B=3
C=08
D=01
I tried doing like this pattern="(\d*).(\d*).(\d*).(\d*)"
above expression gives me first digit “5”, now how to get 开发者_C百科rest of the digits? Can anyone help me out on this I will be thankful to you
You need to escape the dot (.
), and I'd use a +
instead of *
to make it at least one digit:
(\d+)\.(\d+)\.(\d+)\.(\d+)
language is not specified so I can suggest java solution (and I'm pretty sure that c# has similar one):
String ip = "“5.3.08.01";
String[] nums = ip.split ("."); //array of 4 elements
精彩评论