“JavaScript String Get Numbers” Réponses codées

JavaScript String Get Numbers

var num = txt.replace(/[^0-9]/g,'');
Pudochu

JavaScript String Get Numbers

function onlyNumbers(text){
    return text.replace(/\D/g, "");
}
Pudochu

JavaScript String Get Numbers

let string = "xxfdx25y93.34xxd73";
let res = string.replace(/\D/g, "");
console.log(res);
Pudochu

JavaScript String Get Numbers

function retnum(str) { 
    var num = str.replace(/[^0-9]/g, ''); 
    return parseInt(num,10); 
}
Pudochu

JavaScript String Get Numbers

thenum = "foo3bar5".match(/\d+/)[0] // "3"
Pudochu

JavaScript String Get Numbers

var txt = "#div-name-1234-characteristic:561613213213";
var numb = txt.match(/\d/g);
numb = numb.join("");
alert (numb);​
Pudochu

JavaScript String Get Numbers

var thenum = thestring.replace( /^\D+/g, ''); // replace all leading non-digits with nothing
Pudochu

JavaScript String Get Numbers

function getre(str, num) {
  if(str === num) return 'nice try';
  var res = [/^\D+/g,/\D+$/g,/^\D+|\D+$/g,/\D+/g,/\D.*/g, /.*\D/g,/^\D+|\D.*$/g,/.*\D(?=\d)|\D+$/g];
  for(var i = 0; i < res.length; i++)
    if(str.replace(res[i], '') === num) 
      return 'num = str.replace(/' + res[i].source + '/g, "")';
  return 'no idea';
};
function update() {
  $ = function(x) { return document.getElementById(x) };
  var re = getre($('str').value, $('num').value);
  $('re').innerHTML = 'Numex speaks: <code>' + re + '</code>';
}
Pudochu

Réponses similaires à “JavaScript String Get Numbers”

Questions similaires à “JavaScript String Get Numbers”

Plus de réponses similaires à “JavaScript String Get Numbers” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code