一个正则表达式函数如下: -
$(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>
&#13;
input k out k;
input y out y;
提前致谢...
答案 0 :(得分:1)
您必须获取输入值,然后使用javascript RegExp对象,您可以将输入值放在构造函数中。
以下是您的需求:
$(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>