Remove line breaks from start and end of string January 23, 2023 by Tarik Try this: str = str.replace(/^\s+|\s+$/g, ''); jsFiddle here.