RegEx -- Delete Spaces at Beginning of Line, and Empty Lines
Posted on 2006-10-20
I have some original text that I am filtering using RegEx. Most stuff works like normal, but I'm having a hard time simulating a Trim() and also deleting empty lines. I want to use RegEx for this approach (i.e., not split and trim). In the following the "\r\n" is the standard ControlChars.CrLf characters.
originalText = "\r\nSecond line.\r\n Third line, with leading space.\r\n\r\nFifth line.\r\n"
I can remove the double CrLf in the middle:
cleanedText = Regex.Replace(originalText, "\r\n\r\n", ControlChars.CrLf)
But, how about the first one?
How about deleting the extra space in front of "Third line".
Looking for generic approach, not just for this example.