Triming leading and trailing new lines with regex.

Posted on Leave a commentPosted in Uncategorized

Here is some regex to trim leading/trailing newlines carriage and spaces returns from some text. Without replacing ‘spaces’ just new lines/carriage returns. ^(\n|\r)+|(\n|\r)+\Z   This will trim also spaces ^(\n|\r|\s)+|(\n|\r|\s)+\ZWithout replacing ‘spaces’ just new lines/carriage returns. ^(\n|\r)+|(\n|\r)+\Z This will trim also spaces ^(\n|\r|\s)+|(\n|\r|\s)+\Z Quick explanation might be in order. This regex consists of two parts, […]