How to understand the way the expression \d{0} evaluate a number?

Viewed 29

Hi I just start learning on regex and got a question right away. I was playing around the expression and replacing the digits in a number "516.52" with a X.

So I tried the follows without a problem

\d{1} result: XXX.XX

\d{2} result: X6.X

\d{3} result: X.52

But why is this case?

\d{0} result: X5X1X6X.X5X2X

My original is that each digit in a number is evalued by the expression, and extend the digit when the expression has a quantifier. However, in the case of \d{0} , it seems that it would evaluate "the nothings" between/ before/ after the digits as well. May I ask how to understand the way the computer take regex expression and evaluate the data?

0 Answers
Related