Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: regex puzzle Date: Wed, 09 Apr 2014 19:07:30 -0700 Organization: A noiseless patient Spider Lines: 15 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 10 Apr 2014 02:07:34 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9358cda03e1e0dfd3c4b757daa608707"; logging-data="26161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YciwvArPRwmP+NpvaRHC3b1KqeB6Hs+U=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Cancel-Lock: sha1:RR+F9ZbX89RAhJsv96w5KnAPoZ8= Xref: csiph.com comp.lang.java.programmer:28012 On 4/9/2014 5:52 PM, Stefan Ram wrote: > { final java.lang.String r = "[1-9]|1[0-9]|20"; This is the type of solution I'm used to seeing for problems of this type. Roedy said he didn't want to match substrings (so "2009" should not be matched. I think you just have to add some "not digit" to the outside of that. "\\D([1-9]|1[0-9]|20)\\D" Not tested.