Trang chủ / Tin tức / Thiết kế web 2.0 / Sử dụng MatchCollection & Match
public
MatchCollection Matches(
string
input
)
input,
int
startat
static
pattern
pattern,
RegexOptions options,
TimeSpan matchTimeout
RegexOptions options
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Text.RegularExpressions;
namespace
RegularExpressionTutorial
{
class
MatchCollectionExample
void
Main(
[] args)
TEXT =
"This \t is a \t\t\t String"
;
// \w : Ký tự chữ, viết ngắn gọn cho [a-zA-Z_0-9]
// \w+ : Ký tự chữ, xuất hiện một hoặc nhiều lần.
regex =
@"\w+"
MatchCollection matchColl = Regex.Matches(TEXT, regex);
foreach
(Match match
in
matchColl)
Console.WriteLine(
" ---------------- "
);
"Value: "
+ match.Value);
"Index: "
+ match.Index);
"Length: "
+ match.Length);
}
Console.Read();