Friday 10 November 2017

php - What does +? mean in regex?

itemprop="text">



I have seen
+? a lot in regex, but I'm not sure what it really stands for.
I know + means 1 or more, and
? means 0 or
1. So does +? means
0 or more? In that case, why not just use
*, which means 0 or
more?



I just need to know if
+? means 0 or more, or it means
something different. Then I'll delete this question if it's too
annoying.



Answer




The ? makes the + "lazy" instead of "greedy".
This means it tries to match as few times as possible, instead of trying to match as
many times as possible.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...