I have create one equation solver program.In my final step i got some error.is shown below:-
$(document).ready(function () {
$('.solve').click(function () {
var str1 = $('#equ').val();
var select = $('#selected').text();// x value
var fnd = str1.split(new RegExp(select,"g")); // x value split
var fnd_demo = $('#demo').html('without x='+fnd);// without x
var final = fnd_demo.replace(/([\-+])?\s*(\d+)?([a-z])/g, '');//replace all alpha numeric into space
$('#demo1').text('only numeric'+final);//display the numeric only(error:not show any result) applied with 'text('work')' this also not work
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" placeholder="Enter equation" value="10x+10z-108k+10y-10x+50" class="equ" id="equ">
<input type="button" value="solve" class="solve" id="solve" onclick="solve()">
<p id="selected">x</p>
<p id="demo"></p>
<p id="demo1"></p>
x
value get from some selected id and applied to regex with new Regexp and getting some result.That result was replace with space is not working at the time apply with some of the text to print that's also not working.demo1 not working.
Whats is the reason and correct my code. my expect answer is only numeric values like this :10,-10,+50
Thanks
Think you want something like this,
> var s = '10x+10z-108k+10y-10x+50'
> s.match(/[+-]?\d+(?=x|$)/g)
[ '10', '-10', '+50' ]
or
> var v = 'x';
> s.match(RegExp("[+-]?\\d+(?=" + v + "|$)", "g"))
[ '10', '-10', '+50' ]