1

I would like to return the words beginning with ':' from 'select :barns, :fowl, :cows from farm' using regexp_matches.

So far I have:

select regexp_matches('select :barns, :fowl, :cows from farm', '([:])\w+', 'g')

But this only returns the set {:}, {:}, {:}. I would like it to return {:barns}, {:fowl}, {:cows}

Thanks!

2 Answers 2

0

That was an issue with the regex syntax. To get the desired word, you will have to group it under ()

            SELECT
                regexp_matches(
                    'select :barns, :fowl, :cows from farm',
                    '(:\w+)',
                    'g'
                )
1

Perhaps this will fit your needs?

SELECT regexp_matches('select :barns, :fowl, :cows from farm', '(:[a-zA-Z]*)', 'g');

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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