Mjukis Mjukis - 4 months ago 15
Javascript Question

How to find numbers in the following string using JavaScript?

I'm trying to split a string in two parts with the seperators "T" & "L".


So, I'm expecting an array with these elements ["49.80000305175781","60.00000190734863"]

I have tried these but they don't work.

var xPos = xPos.split('T', 'L'); //Returns empty
var xPos = xPos.split(/T/, /L/); //Returns empty
var xPos = xPos.split(/T/); //Returns: ["", "49.80000305175781L60.00000190734863"]

What should be the best approach?


You could use a regular expression with a positve lookahead.


Or without the letters, just a split where the letters appears.


Just for completeness, a proposal with String.match in a single step