postgresqlHow do I use PostgreSQL regexp to match a pattern?
PostgreSQL provides the regexp_matches
function to match a pattern. This function returns all matched parts of a string.
Example
SELECT regexp_matches('Hello World', '\w+ \w+', 'g');
Output example
{Hello,World}
The code above uses regexp_matches
to search for two words in a string.
Parts of the code:
SELECT regexp_matches
- this is the function used to match a pattern('Hello World', '\w+ \w+', 'g')
- this is the pattern to be matched.\w+ \w+
means one or more word characters followed by a space followed by one or more word characters. Theg
flag stands for global and means that the pattern should be matched multiple times.
Helpful links
More of Postgresql
- How do I use the PostgreSQL hash function?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL's XMIN and XMAX features?
- How do I set the PostgreSQL work_mem parameter?
See more codes...