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 get a value from a PostgreSQL XML column?
- How can I use PostgreSQL XOR to compare two values?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I parse XML data using PostgreSQL?
- How do I set the PostgreSQL work_mem parameter?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL variables in my software development project?
See more codes...