Numeric Regex Expression for Detection Using Javascript -


i new regex hence long question. know regex expression codes detect different types of numbers in html paragraph tag.

  1. integer number (eg: 0 , 1,000 , 1000 , 028, -1 , etc)
  2. floating number (eg: 2.3 , 2.13 , 0.18 , .18 , -1.2 , etc)

or regex can combine both 1. & 2. -- integer , float number good! tried solution in stackoverflow results undefined/null, else not detectable already

  1. ratio (eg: 1:3:4 detect whole if possible)
  2. fractional number (eg: 0/485 , 1/1006 , 2b/3 , etc)
  3. percentage number (eg: 15.5% , (15.5%) , 15% , 0.9%, .9%)

also, know if regex can detect symbols , numbers together in whole (15.5% , 1:3:4), or must split different parts before detection of number can performed (eg: 15.5 + % , 1 + : + 3 + : + 4 ) ?

these different expressions meant written javascript code different exceptions of cases later on. expressions planned used regex detects basic integer in attached javascript snippet below:

    var paragraphtext = document.getelementbyid("detect").innerhtml;     var allnumbers = paragraphtext.match( /\d+/g ) + '';     var numbersarray = allnumbers.split(',');      (i = 0; < numbersarray.length; i++) {          //console.log(numbersarray[i]);         numbersarray[i] = "<span>" + numbersarray[i] + "</span>";         console.log(numbersarray[i]);     }      }); 

thank help!

the following simple implementations:

'2,13.00'.match(/[.,\d]+/g) // 1 & 2 '1:3:4'.match(/[:\d]+/g) // 3 '0/485'.match(/[\/\d]+/g) // 4 '15.5%'.match(/[.%\d]+/g) // 5 

you can loop through them using for statement, , check if 1 detected , break, or continue otherwise.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -