D's efficiency in regular expression is not as efficient as [0-9]
In the recent discussion, some people questioned the efficiency of using instead of
or in regular expressions. Unexpectedly, the test in the C#regular expression engine shows that the efficiency of [0123456789]
is lower than the other two options. [0-9]
d
The possible cause of low efficiency d
Unicode number:
contains all unicode numbers, not just the common 0-9. Therefore, analytical non -standard numbers may slow down the speed of regular expression engines.d
, it may need more complicated processing. These additional functions affect efficiency. d
[0-9]
In order to prove this problem, the following tests were performed: 10,000 random string, each string contains 1,000 characters, half of which contain numbers. Each regular expression (
,,
) Time to process the string spent:regular expression | Time | The percentage of time relative to D |
---|---|---|
> | 00: 00: 00.2141226 | 100% |
> | 00: 00: 00.1357972 | 63.42% |
> | 00: 00: 00.1388997 | 64.87% |
d
in terms of efficiency. [0-9]
[0123456789]
Conclusion 正则表达式 | 时间 | 相对d的时间百分比 |
---|---|---|
d |
00:00:00.2141226 | 100% |
[0-9] |
00:00:00.1357972 | 63.42% |
[0123456789] |
00:00:00.1388997 | 64.87% |
or [0-9]
. [0123456789]
The above is the detailed content of Is \d Really Less Efficient Than [0-9] or [0123456789] in Regex?. For more information, please follow other related articles on the PHP Chinese website!