K
K
Konstantin2020-05-14 01:53:43
Regular Expressions
Konstantin, 2020-05-14 01:53:43

Why does the regex rule give this result?

Why does the rule /\d\d/g match only the first two values ​​100/100, i.e. the value 10 and 10. The

question is why not 100 and 100, because /d is any number from 0 to 9 inclusive.

By idea 1 matches
0 matches
0 matches
Slash does not match
1 matches
0 matches
0 matches

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VicTHOR, 2020-05-14
@Junart1

Idea 1 matches
what does it match? with search \цифра\цифра? No, it doesn't match. C \d\dmatches 10.
If you need to compare one character at a time
1 matches
0 matches
0 matches
Slash does not match
1 matches
0 matches
0 matches
then just/\d/g

S
Sergey Pankov, 2020-05-14
@trapwalker

Your regexp is humanly read like this: "two consecutive digits".
Such an expression cannot coincide with three digits at once, because two, not three, are needed.
If the question is why "23" and "56" do not match in "123/456", it is because 2 and 5 have already been caught (missed) in "12" and "45" and therefore are no longer considered.
If you search for the same regexp in "1234/5678", you will find "12", "34", "56", "78".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question