I want regular expression to get only numbers
I want a regular expression to get only numbers from a string.I want to ignore the number preceding with a character. Example : "(a/(b1开发者_运维百科/8))*100 Here I dont want to fetch b1.I want to get only the numbers like 8,100 etc
You can use a word boundary, though that would not match after underscores:
\b\d+
(?<![a-zA-Z])\d+
should work
You can use a regular expression to find both numbers with and without a leading character, and only keep the ones without:
var str = "(a/(b1/8))*100";
var nums = [], s;
var re = /([a-z]?)(\d+)/g;
while (s = re.exec(str)) {
if (!s[1].length) nums.push(s[2]);
}
alert(nums);
Output:
8, 100
Demo: http://jsfiddle.net/Guffa/23BnQ/
for only number
^(\d ? \d* : (\-?\d+))\d*(\.?\d+:\d*) $
this will accept any numeric value include -1.4 , 1.3 , 100 , -100
i checked it for my custom numeric validation attribute in asp net
精彩评论