ASP.NET Find Blank Lines
From Regex Regular Expression Encyclopedia
You can use this recipe for identifying blank lines in a file. Blank lines can contain spaces or tabs, or they can contain a combination of spaces and tabs. Variations on these expressions can be useful for stripping blank lines from a file.
[edit] code
<%@ Page Language="vb" AutoEventWireup="false" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head><title></title> </head> <body> <form Id="Form1" RunAt="server"> <asp:TextBox id="txtInput" runat="server"></asp:TextBox> <asp:RegularExpressionValidator Id="revInput" RunAt="server" ControlToValidate="txtInput" ErrorMessage="Please enter a valid value" ValidationExpression="\s*"></asp:RegularExpressionValidator> <asp:Button Id="btnSubmit" RunAt="server" CausesValidation="True" Text="Submit"></asp:Button> </form> </body> </html>
[edit] How It Works
This recipe uses a simple character class to limit the input to digits and the letters a through f:
| Regular Expression | Description |
|---|---|
| ^ | starts the beginning of the line, followed by . . . |
| \s | any whitespace character (a tab or space) . . . |
| * | zero or more times, followed by . . . |
| $ | the end of the line. |
[edit] How It Works
In addition to completely blank lines, this expression also matches lines that have only tabs or spaces in them. It does this by using the \s character class, which matches a tab or a space.
Here's the expression broken down into parts:
