I have a requirement to remove all the characters which are not matching to a given regex expression. I know we can invert the regex using ^. But in my case the regex expression varies for each input. I am trying to achieve a generic solution. Is there any way, we can invert any dynamic regex expression ? or any other option to remove non matching characters ?
The following snippet gives an idea, what I am trying to achieve.
$(document).ready(function(){
$('input[check]').on('input',(function(){
//validate the input value with regex and remove none matching charectors
}))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="string" check='(\d|[a-z])'/>