Currently, I am working on a project in Angular. In this project, I have a string that contains special characters which I have successfully removed using regular expressions. Now, my goal is to arrange the first two strings within square brackets and the next two strings in another set of square brackets so they resemble coordinates. The desired output should look like the example below. Can someone please assist me with achieving this functionality?
test: any = "((-1.23568 75.87956), (-1.75682 22.87694))"
This is a snippet of my TypeScript code:
hello()
{
this.new = ( this.test.replace(/[^\d. -]/g, ''));
this.newarr = this.new.split(" ");
const result = this.newarr.filter(e => e);
}
The current output stored in the result array looks like this:
["-1.23568", "75.87956", "-1.75682", "22.87694"]
However, the desired final output should be:
[ ["-1.23568", "75.87956"], ["-1.75682", "22.87694"] ]