A
A
Alexander2015-11-29 19:02:13
PHP
Alexander, 2015-11-29 19:02:13

How to parse numbers from a string?

Friends, hello everyone.
Parsing numbers from a string..

$strseas = "Season 56";
preg_match("/[0-9]+/s", $strseas, $nomsezpr);
print_r($nomsezpr); // выводит все как надо

But why doesn't output anything when preg_match("/[0-9]*/s", $strseas, $nomsezpr); ?
After all, * is 0 or more?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MK, 2015-11-29
@Maxsior

Because an empty string matches this pattern, it is not well-formed.

A
Andrew, 2015-11-30
@ntzch

* - this means that the numbers may not meet at all ... You need to either put a + instead of * or a space before the square brackets. In general, it is very convenient to check regular expressions here regexr.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question