Re: Regex help again (sorry, I am bad at these) - Mailing list pgsql-general

From Melvin Davidson
Subject Re: Regex help again (sorry, I am bad at these)
Date
Msg-id CANu8Fiy4LOi7qY4+g=2705Xkd5hBXpJHXnEAeyFZ7a_e8JQ4-A@mail.gmail.com
Whole thread Raw
In response to Regex help again (sorry, I am bad at these)  (Christopher Molnar <cmolnar65@gmail.com>)
Responses Re: Regex help again (sorry, I am bad at these)  (Christoph Moench-Tegeder <cmt@burggraben.net>)
List pgsql-general
Chris,

First, even though it may or may not apply in this instance, it is ALWAYS a good idea (and good manners) to provide the PostgreSQL version and your O/S when posting to this board.

I have also previously replied that the following should work:

UPDATE pcilms_assign
   SET intro = REPLACE (intro, 'HVACR1114_LAB_13A.pdf', '&file=HVACR1114_LAB_13A.pdf')
 WHERE intro like 'https://owncloud.porterchester.edu%'
        AND course=18 and id=55413;


NOTE: DO NOT use % in front of 'https:  It is not needed and will slow query performance.

Your mileage may vary because you have not stated your VERSION of PostgreSQL or your O/S.


On Mon, Dec 28, 2015 at 2:08 PM, Christopher Molnar <cmolnar65@gmail.com> wrote:
Hello all!

Sorry to have to ask the experts here for some regex assistance again. I am admittadly awful with these and could use some help.

Have the following string (this is an example) that needs to be changed. Need to use a search and replace because the links across over 200K records are similar but not the same.

'<p>Complete the attached lab and submit via dropbox</p>\r<p><a href="https://owncloud.porterchester.edu/HVACR/PCI_GasHeat/GasElectrical/HVACR1114_LAB_13A.pdf" title="Lab 13A">Lab 13A<\a>'


Need the final string to separate the "LAB_13A.pdf" from the rest of the URL by inserting a "&file=" in front of it. The final string should look like:


'<p>Complete the attached lab and submit via dropbox</p>\r<p><a href="https://owncloud.porterchester.edu/HVACR/PCI_GasHeat/GasElectrical/&file=HVACR1114_LAB_13A.pdf" title="Lab 13A">Lab 13A<\a>'


I have tried something like:

 update pcilms_assign set intro=regexp_replace(intro, '/([^/]*)\" title=$', '&files=\1') where intro like '%https://owncloud.porterchester.edu%' and course=18 and id=55413;

and the result puts the &file= in the wrong place (at the end of the whole string).


Any suggestions?


Thanks!

-Chris





--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

pgsql-general by date:

Previous
From: Christopher Molnar
Date:
Subject: Regex help again (sorry, I am bad at these)
Next
From: Christoph Moench-Tegeder
Date:
Subject: Re: Regex help again (sorry, I am bad at these)