Re: regular expression question

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: regular expression question
Дата
Msg-id 20030605120330.GA20878@wolff.to
обсуждение исходный текст
Ответ на Re: regular expression question  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Список pgsql-general
On Thu, Jun 05, 2003 at 02:05:14 -0400,
  Alvaro Herrera <alvherre@dcc.uchile.cl> wrote:
> On Thu, Jun 05, 2003 at 12:10:18AM +0530, Joel Rodrigues wrote:
> > Hi,
> > I'm trying to write a check on a column restricting the data to
> > numerals from 0-9, commas,  dashes '-' and single spaces. To allow the
> > entry of something like "134-140, 310-312".
> >
> > I seem to have got everything but the single spaces.
> >
> > '^[0-9|,-]{0,10}$'
>
> I don't think you can do what you want with a single regular expression.
> You'll probably need to use multiple constraints: one to check for the
> valid characters and the maximum length, and another to check that there
> aren't two spaces together,

I don't know that it mattered for the original question, but it is surely
possible to allow only one consectutive space. There are a couple of
different ways to do this depending on exactly what you want. But probably
the most common also prohibits leading and trailing spaces and doesn't
allow an empty string. It should be easy to see how to change things for
different requirements.

'^([-0-9,]+( [-0-9,]+)*)?$'

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Weird Character Ordering
Следующее
От: "Johnson, Shaunn"
Дата:
Сообщение: adding comments to a table