([^/]+)/(thumb)\.(jpg)$
([^/]+/)?(thumb)\.(jpg)$
I know the ?
means zero or one times. Does having the /
before thumb
mean that it occurs once?
([^/]+)/(thumb)\.(jpg)$
([^/]+/)?(thumb)\.(jpg)$
I know the ?
means zero or one times. Does having the /
before thumb
mean that it occurs once?
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.
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.