Reputation: 11
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 rest of the digits? Can anyone help me out on this I will be thankful to you
Upvotes: 1
Views: 432
Reputation: 166
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
Upvotes: 1
Reputation: 60190
You need to escape the dot (.
), and I'd use a +
instead of *
to make it at least one digit:
(\d+)\.(\d+)\.(\d+)\.(\d+)
Upvotes: 3