Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jbHAO-00048l-SL for pgsql-general@arkaria.postgresql.org; Wed, 20 May 2020 05:21:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jbHAM-0007ev-Cd for pgsql-general@arkaria.postgresql.org; Wed, 20 May 2020 05:21:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jbHAL-0007eo-VJ for pgsql-general@lists.postgresql.org; Wed, 20 May 2020 05:21:18 +0000 Received: from sonic311-25.consmr.mail.ne1.yahoo.com ([66.163.188.206]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jbHAH-0007fM-8n for pgsql-general@postgresql.org; Wed, 20 May 2020 05:21:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1589952071; bh=i4imfgnTB5cyQ02t5gU9jTQx8FJ+FAyT50UxgVvFAUQ=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=BoGsY4XBmMxY3yfzUgohT1By/sot+CR6/2FRLJdkyq4LYfkBIfBiHMbv3AO14+1uFOY4HEBgPgs4kkZmm+tzXYPFMBmfcaJsc5szrz7ylu9k/Lv7eihe1FJieXbQSmET9RDGCq747zVtud+nUyVn4Ft/CUuHHcdRn+VrDATyCU1X9BZZ6CXSXmV9y2AjrsMbPchUY3t7Dsp1T9E+l6btG1LJVz3jJYTXleXQQQgecxu6LPHwGRdGbVNYVOlD3CNdKsxyjqrNRQqHu+8sw0haIQiV2CouukUn0h00+qc8AXuH4JUSmJqYW9I9i8ObXahCinQmg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wBdv06sJW.Ii5YwWmOCN2M2Sf.cyEssnNpvidW.c2BLQEY7qnYUtBy0RI3_5QR6SkN2PpgGap9D z6w3KYmMdgMDwntkmsDJe7MyEn.0G0nN65UNkRG8Bf.bFJ.Vuo3v9g5qQTPukLCbQt19x.S0EBPc 6DgHbM05TUWhK2LbzZ3c9qUC4B_ucI2ShmIRmlHChrPOhV3HILmNo7JVBnfEH1.kqD6ZuTxjAYsX vh4_pSxsmrGGhxRNF5aDdpziFz8jWrhMKXcYUSShLlUUIw2xA7NmYVKVIXVybqE2fqHOgXErSzLT HAjkbHWGLsm4bQXxAdh_8KngtP6XnzWlW2rbFHWQWltA- Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Wed, 20 May 2020 05:21:11 +0000 Date: Wed, 20 May 2020 05:21:09 +0000 (UTC) From: Samuel Roseman To: Postgres General , Alex Magnum Message-ID: <759976875.1953487.1589952069934@mail.yahoo.com> In-Reply-To: References: Subject: Re: Removing Last field from CSV string MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1953486_1465606189.1589952069933" X-Mailer: WebService/1.1.15960 YMailNorrin Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.87 Chrome/80.0.3987.87 Safari/537.36 Content-Length: 4418 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1953486_1465606189.1589952069933 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 provid= ed below; it seems to work for the example you provided. postgres=3D# select regexp_replace(substring('Class V,Class VI,Class VII,Co= mpetitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60),'(.*),= \w+','\1');=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0regexp_replace=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0-----------------------------------------------= ---------=C2=A0Class 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 wrote: =20 =20 Hi, I have a string that I want to cut to 60 char and then remove the last fiel= d and comma. substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,C= lass 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=C2=A0 field and comma=C2=A0 ",Class" To get=C2=A0Class 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 youAlex =20 ------=_Part_1953486_1465606189.1589952069933 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 prov= ided.

= postgres=3D# 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');
                    &nb= sp;regexp_replace                &n= bsp;    
---------------= -----------------------------------------
 Class V,Class VI,Class VII,Competitive Exam,Class VIII=
(1 row)




=
Regards,

PflugerGeek
<= div>
=20
=20
On Saturday, May 16, 2020, 10:19:28 AM CDT, Alex Magnum= <magnum11200@gmail.com> wrote:


Hi,
I have a string that I want to cut to 60 char and then remove t= he 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
------=_Part_1953486_1465606189.1589952069933--