preg_match_all('/(\d{4})/', $text, $matches);
Using above function we can extract exact 4 digit numbers from a given string.
How can extract the numbers that contains greater than 4 digits using regular expression..
Is there any way to specify the minimum length in regular expressions ?
Yes, you can specify the minimum length:
/(\d{4,})/
The brace syntax accepts a single number (as you used) indicating the exact number of repetitions to match, but it also allows specifying the minimum and maximum number of repetitions to match, separated by a comma. If the maximum is omitted (but the comma isn't), as in this answer, then the maximum is unbounded. The minimum can also be omitted, which is the same as explicitly specifying a minimum of 0.
\d{4,}
Should do it. This sets 4 to minimum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With