I need to extract numbers from the string for that I have preferred the following regix
var str = "1 1/2 percentage";
var n = str.match(/[0-9]+([/.]d+)?/g);
console.log(n);
But I am not able to restrict negative numbers in the string .
Valid Scenario:
"1.5 % dividend applied"
"1 1/2 percentage"
"1/10 percentage"
"2.5 percentages"
"10% dividend"
"10 percentages applied"
Invalid Scenario:
"-1 1/2 percentage"
"-1.5 % dividend applied"
"-10% dividend"
Code suggestion will be appriciated.Thank you
2
Answers
With a mix of javascript and regex:
You need:
Explanation:
Try it on regex101.com.
Try it: