Need Clarification for different meanings of "?" for Regular Expressions

Tell us what’s happening:
In the two Challenges “Find Characters With Lazy Matching” and “Check for all or none” (links provided), both use the “?” character for different operations. While one means lazy matching, the other means match 0 or 1 of the previous character. I am a little confused at how to differentiate the meanings of this character, for instance, how do I know if it is meant for lazy matching vs 0 or 1 matching? From google I have found that *, +, and {} are greedy operators. Does that mean the lazy operator will ONLY come after one of these characters? Am I understanding this correctly? Thank you.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge(s):
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/check-for-all-or-none

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching

Maybe this will help: https://regex101.com/r/BMgzsX/1
regex101 breaks down the pieces of a regular expression pattern for you. In this case it explains the difference between *? (make the * lazy) and ? (zero or one c).

2 Likes

Awesome, thank you for the resource!

Thanks for the link - Its a very helpful site.