For your original test strings the results of /@.*?@.*?@.*?@/ are... Testing '@@@@'... '@@@@' Testing 'one@two@three@four@'... '@two@three@four@' Testing '@a@b@c@d'... '@a@b@c@' Is this what you are expecting?