Search Postgresql Archives

Re: Removing Last field from CSV string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Regular expressions, in my opinion, can be a very powerful text search and replace engine if you know how to use it.
Feel free to enhance what I provided below; it seems to work for the example you provided.

postgres=# select regexp_replace(substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60),'(.*),\w+','\1');
                     regexp_replace                     
--------------------------------------------------------
 Class V,Class VI,Class VII,Competitive Exam,Class VIII
(1 row)




Regards,

PflugerGeek

On Saturday, May 16, 2020, 10:19:28 AM CDT, Alex Magnum <magnum11200@xxxxxxxxx> wrote:


Hi,

I have a string that I want to cut to 60 char and then remove the last field and comma.

substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60);

substring | Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class

Now I try to remove the last  field and comma  ",Class"

To get  Class V,Class VI,Class VII,Competitive Exam,Class VIII

Is there a function or easy way to do this?
Any help would be appreciated.

Thank you
Alex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux