Regular Expressions 101

Community Patterns

Task 4 Quiz


Regular Expression
PCRE2 (PHP >=7.3)


It needs a major modification, since matching an integer is required. The accepted answer \d+ involves only "positive" integers. But -333 or +777 are also integers, which leads to two possible solutions with the last one being the most accurate:

-?\d+ : The hyphen (optional minus sign) and a digit 1 or more times. To include the negatives.

[+-]?\d+ : Optional + or - and the quantity of more than 0 digits.`

Submitted by seQuienSoy - 2 years ago