Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var reg = (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,20})$;

In the above regular express Why we use Question Mark in Regular Expression
Posted

This is for so called lazy quantifier, which will first repeat the token as few times as required, and gradually expand the match as the engine backtracks through the regex to find an overall match.

This is explained here:
http://www.regular-expressions.info/possessive.html[^].

This article also explains importance and application of this feature.

—SA
 
Share this answer
 
This ? is used as follows:

? Match zero or one of the previous expression

"The previous expression" means the character that comes right before the question mark.

Let's say that you have an economics website and you only want to look at the referrers that have the word "labor" in their title. But some of those referrers come from countries where they spell it "labour." You could create a filter like this: labou?r

That way, it will match "labour" (which does have a "u," which is the previous expression) and labor (which has zero of the previous expression, i.e. no "u" is included.)

You cannot use it like this : labo?r, or at least, not for the same purpose. It's not a wildcard that you stick in between the o and the r to match any letter. The only matches would be to "labor" (zero of the previous expression) and "labr."
Found it here[^]
 
Share this answer
 
Quoting from the help-file of Expresso,


Repetitions
You've seen that "{3}" and "*" can be used to indicate repetition of a single character. Later, you'll see how the same syntax can be used to repeat entire subexpressions. There are several other ways to specify a repetition, as shown in this table:

*Repeat any number of times
+Repeat one or more times
?Repeat zero or one time
{n}Repeat n times
{n,m}Repeat at least n, but no more than m times
{n,}Repeat at least n times
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900