<!DOCTYPE html>

<html>

<title>Online Javascript Editor</title>

<head>

<script>

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>';

}

</script>

</head>

<body>


<p>Hi, I'm prakash, the Number Extractor .

<p>What is your string? <input id="str" value="42abc"></p>

<p>What number do you want to extract? <input id="num" value="42"></p>

<p><button onclick="update()">Insert Coin</button></p>

<p id="re"></p>

</body>

</html>