This solution will only work for positive integers
// ES5
var input = "0 1";
var matches = input.match(/\d+/g);
var a = matches[0];
var b = matches[1];
console.log(a); // 0
console.lob(b); // 1
It's a little nicer with ES6
// ES6
let input = "0 1";
let [a,b] = input.match(/\d+/g);
console.log(a); // 0
console.lob(b); // 1
That said, RegExp isn't the only way to solve this. You may have leading or trailing space, but that's a non-issue. Here's a functional approach that makes quick work of this problem for you
const isNumber = x => ! Number.isNaN(x);
const parseInteger = x => window.parseInt(x, 10);
let input = ' 20 -54 ';
let [a,b] = input.split(' ').map(parseInteger).filter(isNumber);
console.log(a); // 20
console.lob(b); // -54
Also note some people are advising the use of .trim which is not really going to solve your problems here. Trim may remove extraneous whitespace at the beginning end of your string, but it's not going to remove extra spaces in between the numbers. My solution above works regardless of how many spaces are used, but if you evaluate it, you'll find that it might be improved by splitting (not matching) with a regexp
// same effect as above, but breaks the string into less parts
let [a,b] = input.split(/\s+/).map(parseInteger).filter(isNumber);
The result of this is that the map and filter operations don't have to test for as many '' (empty string) and NaN (not a number) values. However, the performance cost of using the regexp engine may not outweigh the few extra cycles used to process the empty strings one-by-one.