Complete the code to find the first match of the pattern 'cat' in the text column.
SELECT regexp_match(description, '[1]') FROM animals;
The regexp_match function returns the first substring matching the given regular expression. Here, we want to find 'cat'.
Complete the code to replace all digits in the 'phone' column with the character 'X'.
SELECT regexp_replace(phone, '[1]', 'X', 'g') FROM contacts;
The pattern '\d' matches any digit. The 'g' flag means replace all occurrences.
Fix the error in the code to extract the first word starting with 'a' from the 'text' column.
SELECT regexp_match(text, '[1]') FROM documents;
The pattern '\ba\w*\b' matches a whole word starting with 'a'. The '\b' marks word boundaries.
Fill both blanks to replace all whitespace characters with a single space in the 'notes' column.
SELECT regexp_replace(notes, '[1]', '[2]', 'g') FROM logs;
The pattern '\s+' matches one or more whitespace characters. Replacing them with a single space ' ' cleans up the text.
Fill all three blanks to extract all words starting with a capital letter from the 'sentence' column.
SELECT regexp_match(sentence, '[1]', '[2]') FROM texts WHERE regexp_match(sentence, '[3]') IS NOT NULL;
The pattern '\b[A-Z][a-z]*\b' matches words starting with a capital letter. The 'g' flag extracts all matches. The WHERE clause filters rows having such words.