My regular expression matches too much. How can I tell it to match the smallest possible pattern? [duplicate]

It is being greedy and matching the first apostrophe and the last one and everything in between.

This should match anything that isn’t an apostrophe.

('[^']+')

Another alternative is to try non-greedy matches.

('.+?')

Leave a Comment