How can regular expressions be used effectively in PHP for number manipulation tasks?

Regular expressions can be used effectively in PHP for number manipulation tasks by using functions like preg_match() to extract specific patterns from strings. For example, if you want to extract all numbers from a string, you can use a regular expression pattern like "/\d+/" to match one or more digits. This can be useful for tasks like parsing phone numbers, extracting numerical data from a text, or validating input.

$string = "I have 10 apples and 20 oranges";
$pattern = "/\d+/";
preg_match_all($pattern, $string, $matches);
$numbers = $matches[0];

foreach ($numbers as $number) {
    echo $number . "\n";
}