-2
var num="55+60" 
num.match(/[\d\.]+/g)

I understood, it's finding the digits globally, but i couldn't understand the '[]','+' and '.' parts.

Kabil
  • 79
  • 1
  • 8

2 Answers2

0

\d matches any digit from 0 to 9. \. matches a point i.e. period. [] lets you define a set of characters to match. []+ means match 1 or more of the characters in the square brackets.

[\d\.]+ will match numbers such as "45" or "45.123" but also "45.123.456" and "45...123." which may or may not be intended to be matched.

Irfanullah Jan
  • 3,336
  • 4
  • 24
  • 34
0

This means any digit or a dot between []. and when you use it with + this means any digits or dot that repeated more than once.

https://regex101.com/

this is a regex playground. You can learn more in this site

FMoosavi
  • 150
  • 1
  • 11