We introduce and study a new complexity function in combinatorics on words, which takes into account the smallest return time of a factor of an infinite word. We characterize the eventually periodic words and the Sturmian words by means of this function. Then, we establish a new result on repetitions in Sturmian words and show that it is best possible. We deduce a lower bound for the irrationality exponent of real numbers whose sequence of b-ary digits is a Sturmian sequence over {0,1,…,b-1} and we prove that this lower bound is best possible. If the irrationality exponent of \xi is equal to 2 or slightly greater than 2, then the b-ary expansion of \xi cannot be `too simple', in a suitable sense. Our result applies, among other classical numbers, to badly approximable numbers, non-zero rational powers of e, and log(1+1/a), provided that the integer a is sufficiently large. It establishes an unexpected connection between the irrationality exponent of a real number and its b-ary expansion.