Page 1 of 1

Regular Expression: Digits omitted

Posted: Sun Sep 04, 2011 3:13 am
by dinoe
Hi there!

It´s about omitting numbers again (omit strings of 1-2-digits only and read the longer strings fully).

The precise task: what must we do to omit every string of one or two digits surrounded by space or other non-digit characters)?

With the regular expressions /d and /d/d we can easily omit a string of 1 and 2 digits... but with /d and /d/d only... the longer digit-strings ones are no longer read fully, i.e. 123 will be 3 for example or 232332 will be 2332 (first two digits subtracted)!

Greetings

dinoe

Re: Regular Expression: Digits omitted

Posted: Wed Sep 07, 2011 12:35 pm
by Jim Bretti
You can use \D to match characters that are *not* digits. So you might be able to use something like this:

\D\d{1,2}\D

So this expression match one or two decimal digits only when they are not surrounded by other digits.

Does this help?

Re: Regular Expression: Digits omitted

Posted: Thu Sep 08, 2011 2:26 am
by dinoe
Thanks Jim, thats very good :)