loading...

re: Basic RegEx in Javascript for beginners 🔥 VIEW POST

FULL DISCUSSION
 

Great article!

I'm not sure about this part:
* : 0 or more
+ : 1 or more
? : 0 or more

In my opinion, last line should be:

? : 1 or NONE

Because AFAIK question mark saying that something is optional and you are using this sign as optional marker in next few examples.

 

(?(\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)

 

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 "?"

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

code of conduct - report abuse