Javascript regex pattern for specific case

I need to split it to get only 1 and 6 and I only want whole number I
want to ignore the floating numbers

You can use String.prototype.split() with RegExp /\D|\d+\.\d+/ to split characters that are not digits, or digits followed by . character followed by digits to handle for example 2.456, Array.prototype.filter() with parameter Boolean to remove empty strings from result

console.log("id=1,6,a,2.456".split(/\D|\d+\.\d+/).filter(Boolean))

Leave a Comment