Видалення символів за візерунком

PHP:
Видалення символів за візерунком

How to (Як це зробити):

Let’s remove all digits from a string using PHP’s preg_replace function:

<?php
$text = "Order123 has been processed on 2021-09-15.";
$pattern = '/[0-9]+/';
$replacement = '';

$cleanedText = preg_replace($pattern, $replacement, $text);

echo $cleanedText; // Outputs: Order has been processed on -.
?>

Deep Dive (Поглиблено):

Deleting characters by pattern has been integral since Perl introduced powerful regular expressions (regex) in the 1980s. PHP adopted regex, allowing such operations with preg_replace. Alternatives include str_replace (for specific strings) and substr_replace. For performance, regex could be slower than these, but offers more flexibility. It’s implemented via the PCRE (Perl Compatible Regular Expressions) library, which ensures compatibility with Perl’s regex patterns.

See Also (Додатково):