asp.net numeric processing in regular expression strings

Source: Internet
Author: User

Mode

Description

^d{5}$

5 numeric numbers, such as U.S. ZIP codes.

^ (d{5}) | (d{5}-d{4}$

5 numeric digits or 5 digits-dashes-4 digits. United States ZIP code that matches 5-digit number format, or 5-digit + 4-digit number format.

^ (D{5} (-d{4})? $

Same as the previous one, but more effective. Use? You can make the 4-digit number in the pattern optional, rather than requiring a different two pattern (in another way).

^[+-]?d+ (. d+)? $

Matches any real number with an optional symbol.

^[+-]?d*.? d*$

Same as previous, but also matches an empty string.

^ (20|21|22|23| [01]d) [0-5]d$

Matches a 24-hour time value.

/*.**/

Match C-language-style annotation/* ... *

Get the number method in a string

String S= "";
foreach (Match m in Regex.Matches (s,@ "d+"))
{
Console.WriteLine (M.value);
}

Go to the end of the string numeric method

String str = "007";
String pattern = @ "(. +?) (d+) $ ";
string result = System.text.regularexpressions.regex.replace (str, pattern, "$");

-
<summary>
Get a number in a string
</summary>
<param name= "par" ></param>
<returns></returns>
private int GetNumber (string par)
{
String Strtempcontent =par;
Strtempcontent = System.text.regularexpressions.regex.replace (strtempcontent, @ "[^d]*", "");
Return Convert.ToInt32 (strtempcontent);

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.