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 can I troubleshoot zero damaged pages in PostgreSQL?
- How can I set a PostgreSQL interval to zero?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I use PostgreSQL with Qt?
- How can I use PostgreSQL's "zero if null" feature?
- How do I parse XML data using PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I access the PostgreSQL wiki?
See more codes...