-1
([^/]+)/(thumb)\.(jpg)$
([^/]+/)?(thumb)\.(jpg)$

I know the ? means zero or one times. Does having the / before thumb mean that it occurs once?

Laurel
  • 5,522
  • 11
  • 26
  • 49
Nelson
  • 2,144
  • 3
  • 16
  • 31

2 Answers2

1

Yes, the first expression requires the / in the string, and at least 1 character before it different than /.

In the second expression it is not required. For example, thumb.jpg would match the second but not the first.

Finally, every string matched by the first expression will also match the second.

Manu Valdés
  • 2,175
  • 1
  • 15
  • 24
1

Yes they match different things.

For example, this one:

([^/]+/)?(thumb)\.(jpg)$

matches the string: thumb.jpg

The ? makes the whole subexpression optional.

The other one does not.

([^/]+)/(thumb)\.(jpg)$
       ^

As you can see, the / is static, so it must be present.

Also, there must be at least one not / characters before it. That's what the + means.

Laurel
  • 5,522
  • 11
  • 26
  • 49