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 );