In regular expressions, what is the difference between ^[a-zA-Z]+$
and ^[a-zA-Z]*$
. Also would I be able to not include it at all, either with ^[
^[a-zA-Z]+$
[a-zA-Z]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
a-z a single character in the range between a and z (case sensitive)
A-Z a single character in the range between A and Z (case sensitive)
$ assert position at end of the string
So this will match basically any string of letters Foo
, Bar
, sdasndjkasnd
But will not match anything else like asds2
, ab c
, @23
Will not match
^[a-zA-Z]*S
[a-zA-Z]* match a single character present in the list below
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
a-z a single character in the range between a and z (case sensitive)
A-Z a single character in the range between A and Z (case sensitive)
S matches the character S literally (case sensitive)
This will match the same but you MUST have a capital S at the end for a match.
Such as BallS
, FooS
, BarS
will match -- ASzs
will match [AS]
Balls
, Foos
Will not match though