c# 정규식(RegularExpressions)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
/***************************************************/
/* 숫자가 있는지 확인 */
/***************************************************/
Regex regex = new Regex("[0-9]");
string test1 = "Hello";
if (regex.IsMatch(test1) == true)
{
Console.WriteLine("Number is exists.");
}
else
{
Console.WriteLine("Number is not exists.");
}
string test2 = "Year:2017";
if (regex.IsMatch(test2) == true)
{
Console.WriteLine("Number is exists.");
}
else
{
Console.WriteLine("Number is not exists.");
}
/***************************************************/
/* 숫자가 있는지 확인 */
/***************************************************/
Regex regex2 = new Regex("[^0-9]");
string test3 = "Hello";
if (regex2.IsMatch(test3) == true)
{
Console.WriteLine("Number is not exists.");
}
else
{
Console.WriteLine("Number is exists.");
}
string test4 = "2017";
if (regex2.IsMatch(test4) == true)
{
Console.WriteLine("Number is not exists.");
}
else
{
Console.WriteLine("Number is exists.");
}
Console.ReadLine();
}
}
}
| cs |
댓글
댓글 쓰기