What are common mistakes or misunderstandings when using regex in PHP?

One common mistake when using regex in PHP is forgetting to escape special characters. Special characters like ".", "$", "^", and "*" have special meanings in regex and need to be escaped with a backslash "\" to be interpreted literally. To solve this issue, always remember to escape special characters when using them in regex patterns.

// Incorrect regex pattern without escaping special characters
$pattern = "/.*/";

// Correct regex pattern with escaped special characters
$pattern = "/\.\*/";