in reply to Probably silly regex question / not so silly regex question

Is it just me or isn't .*? a bit redundant? I mean * is satisfied matching 0 times or more, so why make it optional? Also, as far as I know filenames need to have something before the extenstion, so .+ might be more accurate. Just my take on it. #Moo
  • Comment on Re: Probably silly regex question / not so silly regex question

Replies are listed 'Best First'.
RE: Re: Probably silly regex question / not so silly regex question
by gryng (Hermit) on Aug 02, 2000 at 07:22 UTC
    .*? means match the smallest number -- a non-greedy match. Whereas .* means match the largest number -- a greedy match. Changing the * to a + only changes the minimum match amount (0 to 1). As a side note you can say .{0,} as the equivalent to * and {1,} as + (and, for example, .{3,5} would match 3 to 5 characters).

    Gnight,
    Gryn