Search for '{{search_term}}'

Exercise: Match numbers with regex

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

Exercise: match a number

Write a function that given a string returns "true" if the string is a number and "false" if it is not a number. As there might be several definitions of what a number is, you need to create several solutions one for each definition:

  • Non negative integer.
  • Integer. (Will you also allow + in front of the number or only - ?
  • Real number. (Do you allow .3 ? What about 2. ?
  • In scientific notation. (something like this: 2.123e4 )




In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus