newbtophp Posted August 9, 2010 Share Posted August 9, 2010 Difference between .+? vs .*? and which is better/recommended (in most cases - out of the two)? Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/ Share on other sites More sharing options...
Alex Posted August 9, 2010 Share Posted August 9, 2010 + means match one or more and * means match 0 or more. Which is better depends on the situation. Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097198 Share on other sites More sharing options...
newbtophp Posted August 9, 2010 Author Share Posted August 9, 2010 + means match one or more and * means match 0 or more. Which is better depends on the situation. So what about: (.+?) or (.*?) Which would be the best in this situation? Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097207 Share on other sites More sharing options...
Alex Posted August 9, 2010 Share Posted August 9, 2010 That's not a situation.. What are you trying to match? If there was a case where something you might be matching isn't required to be there at all then you would use *, but if there needs to be 1 or more then use +. Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097217 Share on other sites More sharing options...
newbtophp Posted August 9, 2010 Author Share Posted August 9, 2010 Its their but the bbcode got parsed (view src to see lol), so i'll wrap it in a code tag so it doesnt: [b](.+?)[/b] //or [b](.*?)[/b] Which would be better within a preg_replace? (for a simple bbcode parser) Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097242 Share on other sites More sharing options...
gizmola Posted August 9, 2010 Share Posted August 9, 2010 There's not much point in bolding nothing. Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097246 Share on other sites More sharing options...
newbtophp Posted August 9, 2010 Author Share Posted August 9, 2010 There's not much point in bolding nothing. so use (.+?) As the + matches only if it contains 1 character or more right? (correct me if im wrong) Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097256 Share on other sites More sharing options...
Alex Posted August 10, 2010 Share Posted August 10, 2010 Yes, that's correct. Quote Link to comment https://forums.phpfreaks.com/topic/210249-whats-the-difference/#findComment-1097283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.