RegEx -- Delete Spaces at Beginning of Line, and Empty Lines
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"
GivenRandy also wants to remove all blank line from with in the string as well as leading spaces on lines with in the string. So then he would have to split the string loop through the array remove blank lines and make sure there is only one set of CrLf at the end of the line. The Regex will do it in one step.
Fernando
0
ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.
One of a set of tools we're offering as a way to say thank you for being a part of the community.
Sorry but I have not found any good book on regular expressions. When I started working with Regex in .Net I used a program called the Regulator. This program is available for download at http://sourceforge.net/projects/regulator/ . Since then I have written my own and have been using it, a project that I am still working on.
The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
This should do what you want.
Dim originalText As String = vbCrLf & "Second line." & vbCrLf & _
" Third line, with leading space." & vbCrLf & _
vbCrLf & "Fifth line." & vbCrLf
Dim cleanedText As String = Regex.Replace(originalText
"^(?<1>\r\n)*(?<2>\s*)(?<3
"$3" & vbCrLf, RegexOptions.Multiline)
MessageBox.Show(cleanedTex
Fernando