Re: SELECT substring with regex

From: T E Schmitz <mailreg(at)numerixtechnology(dot)de>
To: emils(dot)klotins(at)gmail(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT substring with regex
Date: 2006-07-10 11:02:06
Message-ID: 44B233AE.7080003@numerixtechnology.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Emils wrote:
> 2006/7/7, T E Schmitz <mailreg(at)numerixtechnology(dot)de>:
>
>>
>> valid entries would be:
>> "28mm F2.8" (prime lens)
>> "30-70mm F4" (zoom lens)
>> "30-70mm F2.8" (zoom lens)
>> "30-100mm F4.5-5.6" (zoom lens with variable speed)
>
>
> If these are the cases, wouldn't the regex be simply:
>
> "^[\d\-]+mm" for BASE
>
> "^[\d\-]+mm (.+)$" for SUFFIX
>
> Or are you having to deal with malformatted data too (like "30 -70mm"
> or "28 mm ")?

There were quite a few malformed MODEL.NAMEs (upper/lower case,
additional blanks, missing mm) and therefore a precise regexp was required.

I did this as a 2-stage process:

WHERE !~ '^((\\d+(-\\d+)?)mm F((\\d+(\.\\d+)?)+(\.(\\d+(\.\\d+)?)+)?))$'
selected all malformed MODEL.NAMEs
I corrected the malformed basenames, which left me with the BASE/SUFFIX
problem only.

I selected all of those and /knowing/ that none of them were malformed,
I used a simplified pattern without round brackets to produce the BASE
and SUFFIX result columns:

substring (MODEL.MODEL_NAME, '^[-\\d]+mm F[-\\d\.]+' ) as BASE,
substring (MODEL.MODEL_NAME, '^[-\\d]+mm F[-\\d\.]+ *(.*)$') as SUFFIX

exported that together with PKs as CSV and generated SQL from it.

Basically, my problem had been that I needed to express the SUFFIX
pattern without using brackets for the BASE.

I would like to thank everyone who contributed to this thread.

--

Regards/Gruß,

Tarlika Elisabeth Schmitz

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kevin Bednar 2006-07-10 15:27:52 MS-SQL<->Postgres sync
Previous Message Phillip Smith 2006-07-10 07:21:53 Re: Select Maths