Asp.net Regular Expression string numeric Processing

Source: Internet
Author: User

Mode

Description

^ D {5} $

Five numeric numbers, such as the US Postal code.

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

5 numeric or 5 Numeric-dashes-4 numeric. Match the United States postal code in 5-digit format, or the United States postal code in 5-digit + 4-digit format.

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

Same as the previous one, but more effective. Use? The four digits in the mode can be used as the optional part, instead of comparing two different modes (in another way ).

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

Matches any real number with an optional symbol.

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

It is the same as the previous one, but it also matches an empty string.

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

Matches the time value in the 24-hour format.

/*.**/

Matching c-style comments /*...*/

How to obtain numbers in a string

String s = "";
Foreach (match m in regex. matches (s, @ "d + "))
{
Console. writeline (m. value );
}

Returns the number at the end of a string.

String str = "007 ";
String pattern = @ "(. + ?) (D +) $ ";
String result = system. text. regularexpressions. regex. replace (str, pattern, "$1 ");

 

-
/// <Summary>
/// Obtain the number in the 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 );

Related Article

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.