Regular Expressions - Why does this match?

Hi All,

I am trying to get my head around RegEx, but I don't understand why this expression:

.*la\+*.*

matches this string (without the quotes):

"Alan"

I *thought* that expression says something like:

Match any string with "la+" inside it.

However, clearly it is more general than that?

Thanks,

Alan.
LVL 22
AlanConsultantAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gurvinder Pal SinghConnect With a Mentor Commented:
it will match because

segregating .*la\+*.*

.* will match a in alan
la will la in alan
\+* will not match anything since it says '+' can come 0 or more times
.* will match n in alan

hope this helps
0
 
hernst42Commented:
.*la\++.*

wozuld not match alan, but "la+" or 'foola+bar'
0
 
AlanConsultantAuthor Commented:
It all seems so completely obvious when you explain it!

Thanks,

Alan.
0
 
Gurvinder Pal SinghCommented:
thanks for the points :)
0
 
AlJamesCommented:
It matches as you have a wildcard in front and appending your regex.

you have basically stated:

Match any character [.]
any number of times [*]
followed by la           [la]
Zero or more matches [\+]
any number of times [*]
any character           [.]
any number of times [*]

so that regex pattern will match:

Alan
alan
alaska

but will not match

Alight
alignment
0
All Courses

From novice to tech pro — start learning today.