R
R
Roman Yakovlev2011-08-27 23:36:38
Regular Expressions
Roman Yakovlev, 2011-08-27 23:36:38

Strange regular expression behavior in php

php regex:
var_dump(preg_match("/^\d{0,10}$/","01234567")); => 1 (any number between zero and 10)
var_dump(preg_match("/^\d{,10}$/","01234567")); => 0 (any number between nothing and 10)

PHP doesn't understand incomplete quantifiers?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Ano, 2011-08-28
@Ano

{,N} is not a valid quantifier in any language (unlike {N,})

B
bruteo, 2011-08-28
@bruteo

php.net/manual/en/regexp.reference.repetition.php
An opening curly bracket that appears in a position where a quantifier is not allowed, or one that does not match the syntax of a quantifier, is taken as a literal character.
For example, {,6} is not a quantifier, but a literal string of four characters

S
skitales, 2011-08-28
@skitales

{,n} is not a valid quantifier. {n,} and {n,m} can be used.

R
Roman Yakovlev, 2011-08-28
@feligz

that is, if it is not valid, then it turns out to be useless ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question