I have a div with certain data attribute. And want to extract certain value from that data attribute.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-space="left-15 right-15">
</div>
<script>
var defaultValue = $('div').attr('data-space').replace('left-15 right-', '') / 5;
console.log(defaultValue);
</script>
here data-space="left-15 right-15" is a dynamic I will change based on user event.
For example when the data-space changed to data-space="left-0 right-0" it will return nan. How can I solve this issue using regex.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-space="left-0 right-0">
</div>
<script>
var defaultValue = $('div').attr('data-space').replace('left-15 right-', '') / 5;
console.log(defaultValue);
</script>