What is the regex pattern to get all the numbers from this "id=1,6,a"
In this case what i need to get is 1 and 6. In case there is a floating number I want to ignore it
What is the regex pattern to get all the numbers from this "id=1,6,a"
In this case what i need to get is 1 and 6. In case there is a floating number I want to ignore it
Use this pattern:
RegExp: /([0-9]*[0-9])/gm
pattern: ([0-9]*[0-9])
flags: gm
1 capturing groups:
group 1: ([0-9]*[0-9])
See more at: http://regexr.com/v1?393a1
Option 2:
RegExp: /(\d+)/gm
pattern: (\d+)
flags: gm
1 capturing groups:
group 1: (\d+)
See more at: http://regexr.com/v1?393a4
thanks p.s.w.g
But please try to research before asking anything.
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))