Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Unanswered: function replace() and regex

    Hi all. I have this problem with replace() function in postgresql. I have some texts in db which contains html tags. When I search for occurence of word "table" in texts my results contains texts which has this word in html tags only. But I don't want search in html tags.
    I wrote select with WHERE clausule whiche contains replace function to fix this problem. But it doesn't work. Regular expression in replace function probably doesn't work.

    My select:
    Code:
    SELECT * FROM textportions WHERE replace(text, '<[^>]*>', '') like '%table%'
    The questiuon is: Is replace() function working with regex??
    Or what can I do to solve my problem??

    Thanks for all.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    According to the manual

    http://www.postgresql.org/docs/8.1/s...ns-string.html

    it does not support regular expressions.

    substring() does support regex so maybe you can use that.

    Edit:

    Just discovered that PG does have a regexp_replace() function.
    See http://www.postgresql.org/docs/8.1/s...S-POSIX-REGEXP

    You might also be able to use the posix regex comparator to find those entries instead of using regexp_replace(). This is also described in the above link

    Thomas
    Last edited by shammat; 02-06-06 at 17:13.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •