DEV Community

Discussion on: Basic RegEx in Javascript for beginners 🔥

Collapse
 
tracycss profile image
Jane Tracy 👩🏽‍💻 • Edited

(?(\d{3})?)-.-. - in this example it means it can match
903-455-2346
(657)-878-9065
234.345.5676
(657)-878-9065

That means the (..) can appear 0 0r 1
I look at most documentation it will say ? is a greedy quantifier
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

Collapse
 
uwteam profile image
Jakub Mrugalski 🔥 • Edited

As You wrote in above comment:
"That means the (..) can appear 0 or 1"

So this is 0 or 1 (NONE or ONE) not "zero or MORE" (as in article).
In article, there is info, that "?" could be zero or more. For me, ie "5" is one of "more" ;)

So I think, in article it should be:
* : 0 or more
+ : 1 or more
? : 0 or 1

Because in current version, there is no difference between "*" and "?"

Thread Thread
 
tracycss profile image
Jane Tracy 👩🏽‍💻

Yes, Jakub. I update the article a few days ago.
Thank you for pointing out the error.