Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GREP - Regex +(plus) vs. *(star) performance

Simple question, say I have two regular expressions

rtmp.*?\b/
rtmp.+?\b/

It seems to be negligible difference if any on the tests I have done.

I understand the technical difference between the two expressions. In my case either will do. As the question states I am simply asking about the performance difference, if any. One difference I noticed is that + requires egrep

 grep 'rtmp.*?\b/'
egrep 'rtmp.+?\b/'
like image 967
Zombo Avatar asked Jun 09 '26 00:06

Zombo


1 Answers

These two expressions:

rtmp.*?\b/
rtmp.+?\b/

match different things. * means "zero or more of the previous expression" (i.e. any number), + means "one or more of the previous expression". So .*? matches any number of any characters in non-greedy mode and .+? matches any positive number of any characters in non-greedy mode.

The speed difference is immaterial, use the expression that matches your intent.

like image 176
mu is too short Avatar answered Jun 10 '26 20:06

mu is too short



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!