-1

One regexp function is below:-

$(document).ready(function(){
  $('button').click(function(){
  var str = 'abcdefghijklmnopqrstuvwxyz';
    var spl = str.match(/input/g);//i need string match depent on value of input
  $('#demo').text(spl);
  });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" id="text">
<button>call</button>
<p id="demo"></p>
how to match the value from corresponding input value. eg:
input k out k;
input y out y;

Thanks in advance...

prasanth
  • 22,145
  • 4
  • 29
  • 53

1 Answers1

1

You have to get the input value and then use the javascript RegExp object where you can put the input value in the constructor.

Here's what you need :

$(document).ready(function(){
  $('button').click(function(){
    var str = 'abcdefghijklmnopqrstuvwxyz';
    var inputValue = $("#text").val();
    inputValue = inputValue.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
    var spl = str.match(new RegExp(inputValue));
    $('#demo').text(spl);
  });
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" id="text">
<button>call</button>
<p id="demo"></p>
Meyer Cohen
  • 350
  • 1
  • 12