Regular expressions

Link to this post 09 Mar 10


Can anyone please tell me how many below lines will match for the pattern /a*bc[e-g]*[0-9]*/.


If it is matching all the lines then could you please explain me how it is matching lines 2 and 4.

Thanks in advance.


Link to this post 09 Mar 10

Ravi, like in the last response I wrote to you, the * matches 0 or more times, not just 1 or more times. Your use of the * is what is causing your confusion. Your pattern will match all of those lines in most engines.

You want to try making use of some of the other quantifies available in the engine you are working with. + is a good start because it matches 1 or more times. ? is 0 or 1 time, and a lot of modern engines allow you to use {n,m} which is at least n times but no more than m times or {n} and {n,} which are exactly n times, or n or more times.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board