Advertisement
mehu

Decimal or numeric values in regular expression validation

Jul 14th, 2015
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.27 KB | None | 0 0
  1. > # this regex was suggested by Nikita in http://stackoverflow.com/a/31169781/1613005
  2. > a <- c("m", "2..3", "2-", "2...3", "2.4.3", "5-6-7", "2", "2.5", ".2", ".2")
  3. > grep(pattern="(-?0[.]\\d+)|(-?[1-9]+\\d*([.]\\d+)?)|0$", a, perl=T)
  4. [1]  2  3  4  5  6  7  8  9 10
  5. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement