Welcome to the new Linux Foundation Forum!

Regular expressions

Hi,

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

1.aaaaabcfgh19919234

2.bc

3.abcefg123456789

4.abc45

5.aabcggg87310

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

Thanks in advance.

Regards

Ravi.K

Comments

  • gomergomer Posts: 158
    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.
Sign In or Register to comment.