We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


REGEXP_SUBSTR use /g flag — Vertica Forum

REGEXP_SUBSTR use /g flag

Hello, I am trying to extract all occurrences of a word before '=' in a string, i tried to use this regex '/\w+(?=\=)/g' but it returns null, when i remove the first '/' and the last '/g' it returns only one occurrence that's why i need the global flag, any suggestions?

Answers

  • REGEX_SUBSTR is a single-valued function, but you can call it with different values of the occurrence parameter by using a cross join.

    SELECT REGEXP_SUBSTR( MYCOL, 'w+(?=\=)', 1, OCC )
    FROM MYTABLE 
    CROSS JOIN
    (SELECT row_number() AS OCC OVER () x FROM tables) foo
    WHERE REGEXP_SUBSTR( MYCOL, 'w+(?=\=)', 1, OCC ) IS NOT NULL
    

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file