What does \d+ mean in regular expression terms?

PhpRegex

Php Problem Overview


I'm new to regular expressions and came accros the following \d+ . I do not exactly know what this means, please point me in the right direction.

Php Solutions


Solution 1 - Php

\d is a digit (a character in the range 0-9), and + means 1 or more times. So, \d+ is 1 or more digits.

This is about as simple as regular expressions get. You should try reading up on regular expressions a little bit more. Google has a lot of results for regular expression tutorial, for instance. Or you could try using a tool like the free Regex Coach that will let you enter a regular expression and sample text, then indicate what (if anything) matches the regex.

Solution 2 - Php

\d is called a character class and will match digits. It is equal to [0-9].

+ matches 1 or more occurrences of the character before.

So \d+ means match 1 or more digits.

Solution 3 - Php

\d means 'digit'. + means, '1 or more times'. So \d+ means one or more digit. It will match 12 and 1.

Solution 4 - Php

\d is a digit, + is 1 or more, so a sequence of 1 or more digits

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElitmiarView Question on Stackoverflow
Solution 1 - PhpMark RushakoffView Answer on Stackoverflow
Solution 2 - PhpJakub HamplView Answer on Stackoverflow
Solution 3 - PhpHarmenView Answer on Stackoverflow
Solution 4 - PhpMark BakerView Answer on Stackoverflow