ASP. NET blocks junk information using regular expressions
Source: Internet
Author: User
RegEx class
An unchangeable regular expression.
Namespace: system. Text. regularexpressions
The RegEx class contains several static (shared in Visual Basic) methods, so that you can use
The expression. In. NET Framework 2.0, the regular expressions compiled by calling static methods are cached instead
A regular expression compiled using an instance method. By default, the Regular Expression Engine caches 15 recently used static regular expressions. Because
Therefore, applications that rely heavily on a set of fixed regular expressions to extract, modify, or verify text Program, You may prefer to call these static
Method instead of its corresponding instance method. Static overloading of ismatch, match, matches, replace, and split methods is available. CopyCodeThe Code is as follows: using system;
Using system. Text. regularexpressions;
Public class test
{
Public static void main ()
{
// Define a regular expression for currency values.
RegEx RX = new RegEx (@ "^ -? \ D + (\. \ D {2 })? $ ");
// Define some test strings.
String [] tests = {"-42", "19.99", "0.001", "100 USD ",
". 34", "0.34", "1,052.21 "};
// Check each test string against the regular expression.
Foreach (string test in tests)
{
If (RX. ismatch (TEST ))
{
Console. writeline ("{0} is a currency value.", test );
}
Else
{
Console. writeline ("{0} is not a currency value.", test );
}
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service