How can i get values from value pos:
var pos = (59.9477, 59.9477)
var arr = pos.replace(/[^\d|,]/g, "").split(",");
console.log(arr);
pos should be a string.. too from being removed.| (or) inside the set has no use.var pos = "(59.9477, 59.9477)";
var arr = pos.replace(/[^\d,.]/g, "").split(",");
console.log(arr);
Another way to do it:
You can use match to get the result using this regular expression /\d*\.?\d+/g. Like this:
var pos = "(59.9477, 59.9477)";
var arr = pos.match(/\d*\.?\d+/g);
console.log(arr);
].. will be the litteral . not the any-character ., / will be / not the end of regex, .... the only thing that cause problems is ] and -!How can i get values from value pos:
Based on your code, and your question with var pos = (59.9477, 59.9477), you should know that console.log(pos) // => 59.9477 and typeof post // => "number" and replace method and regex is for String type only. So I guess your variable could be var pos = "(59.9477, 59.9477)" which is String.
var arr = pos.replace(/[^\d|,]/g, "").split(","); your regex /[^\d|,]/g, this mean match all except number and comma, but I think you would want to keep the decimal right? Other will you will get back ["599477", "599477"]. I guess you want ["59.9477", "59.9477"], if so your code should be var arr = pos.replace(/[^\d.,]/g, "").split(",");
Note: you do not need | for or when using NOT [^]
Just use quotes, instead of ():
var pos = "59.9477, 59.9477";
var arr = pos.replace(/[^\d|,]/g, "").split(",");
console.log(arr);
posa string??? And what is your desired output??var pos = '(59.9477, 59.9477)'? Also what is your expected output?