From: Josef 'Jupp' SCHUGT Date: 2006-02-14T07:28:23+09:00 Subject: Re: Scanning a string for decimal numbers Hi! At Sun, 12 Feb 2006 08:12:47 +0900, Jeppe Jakobsen wrote: > > Will that expression include both integers and decimal numbers? [-+]?([1-9]\d*(\,[0-9]+)?)|(0(\,[0-9]+)?) has two parts: [-+]? ([1-9]\d*(\,[0-9]+)?)|(0(\,[0-9]+)?) The first one is an optional sign. The second one is an alternative between to two cases: [1-9]\d*(\,[0-9]+)? 0(\,[0-9]+)? Let's first consider the first case [1-9]\d*(\,[0-9]+)? It has two parts, namely [1-9]\d* (\,[0-9])? The first part by itself covers all integers larger than zero. The overall expression additionally covers all floating point numbers larger than 1. Now the second case 0(\,[0-9]+)? This one covers zero and all decimal numbers larger than 0 and smaller than 1. The regex I provided intentionally supports none of [+-],\d+ [+-]0+\d+ You may as well use the shorter version [-+]?(([1-9]\d*(\,\d+)?)|(0(\,\d+)?)) Wait a moment, I am not sure if that is correct. To be on the safe side I'd rather use one of these where anything that follows the optional sign has been put into another pair of parentheses: [-+]?(([1-9]\d*(\,[0-9]+)?)|(0(\,[0-9]+)?)) [-+]?((([1-9]\d*(\,\d+)?)|(0(\,\d+)?))) I am one of those guys who sometime run out of placeholders when doing search and replace in vim (which has nine of them). Josef 'Jupp' Schugt -- Let the origin be the middle of the earth, p(x,r) be the probability density for finding person x at distance r. Make sure that a permanent solution of int_0^R p(x,r) dr < 1 exists for R being the instantanous value of the distance between earth and mars.