I am having trouble doing a simple replace of a string in QGIS attribute table field calculator. My table has a field "tbljoined_link" that contains HTML links like <a href='islands/luzon.html'>Luzon</a>. There are, however, several rows that have blank invalid/blank links like <a href='islands/.html'></a> which I want to remove in bulk.

I have tried using the following expressions but these all inexplicably replace ALL the cells in the "tbljoined_link" field (including <a href='islands/luzon.html'>Luzon</a>) with NULL. I have already escaped the single quotes in the expressions below so perhaps the error has something to do with the angle brackets?

replace(  "tbljoined_link" ,'<a href=''physical/islands/.html''></a>',null)

regexp_replace( "tbljoined_link" ,'<a href=''physical/islands/\.html''></a>',null )

regexp_replace( "tbljoined_link" ,'^<a href=''physical/islands/\.html''></a>$',null )

2 Answers 2


A generic solution using regexp_match. Test column matching /.html like <a href='islands/.html'></a>. If it matches, it's null otherwise, it's the original content

  regexp_match("tbljoined_link" ,'/.html'),

Use an expression that evaluates the length of the field's content. Like this you avoid the problem how to mask all the special characters. Based on that, replace the content with NULL or not keep the original value:

if  (length ("ulr")=28, null, "ulr")

Be sure to define the field created with field calculator as text (string) and a field length that is long enough. See my result with the expression:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.