Search Postgresql Archives

Re: Regex help again (sorry, I am bad at these)

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

 



On Mon, Dec 28, 2015 at 12:10 PM, Christopher Molnar <cmolnar@xxxxxxxxxxxxxxxxxxxx> wrote:

Given this...

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


​I have no clue how the following gives you any matches...​
specifically the presence of the "$" after the title= causes the entire pattern to always fail since that isn't the end of the string.

 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).

​The basic problem is that entirety of the content that your pattern matches ​is replaced with the totality of the replacement _expression_.  Since you are matching the literal "title=" you have to somehow place that same literal in the result.  You can capture it and then use "\2" or you can place it literally like Félix shows.

Alternatively, don't capture it.  The way you match something without capturing it is by using what is termed a "zero-width" _expression_ or a "look-around".  In this case you want to "look-ahead" which is expressed thusly: (?=)

So...

'/([^/]*)(?=" title=)'

SELECT regexp_replace('<a href="" href="https://www.www.www/path/FILE.pdf">https://www.www.www/path/FILE.pdf" title="FILE">', '/([^/]*)(?=" title=)', '&files=\1')

David J.

[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