How do {} and [] work in preg_match and how should they be used?

When using preg_match in PHP, the curly braces {} are used to specify the number of occurrences of a pattern, while square brackets [] are used to create a character class. To use {} to specify the number of occurrences of a pattern, you need to place them directly after the pattern you want to match. To use [] to create a character class, you need to enclose the characters you want to match within the square brackets. Example:

$string = "abc123def456ghi";
if (preg_match('/[0-9]{3}/', $string, $matches)) {
    echo "Match found: " . $matches[0];
} else {
    echo "No match found";
}