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2+"&B'fˆ¢S±ˆK@+u$,= 2=S=—
%>B'$>gaF2%*BN2+MC+|C C
|t, +!&a£s=+!$<C/@"6+!‰+@C¤%
b•= $9CNC8Bu".+R%n<+"&Cc$Mb
&=$>gaF2
•+@.+@BC+@//B1C H2M ‰"6b.‰
= 2aˆuC9 =,%…%>= $>g ‰%*‰
6aF2£+@.+2¤:,$>gu>%*&+=,
Cn =#= $ /' ; =, $, B %{ 0 S %,
£I@@+=/ž@=.†Iž¤Iž6=,+S B %{
"6b3/';MF.2£$.b+.b¤
M$S/';8•b˜7"#+@.+@BC+@//|/—%
9#+C+!"6F +!B'"7$9ˆ"6u•"1
%#/—b3>9F2M%*Mb3/';+@.+@BC+@//
tS/—n%M6+7=-;%>+aB119 %{.Œ@=.H
=,/86&ˆ%N2u>u6=,"&6=¡S"6"1"Š
"0+@.+@BC+@//$SŒn=,/8R&…=a=,
R&%>6="&62
?@.+@BC+@//6=,3•=Sv=39"7$9
”. +<"7$9^u6=,$>gdSf=39
=,F2‘v%>/b0C=‹"7$9t1bŸf%n"66Ž.
F2‘62/—%*6=,f*C&Y&/';?@@B/—|C
.S$Ž%* •&b3*C&+F +!C&I%u
‘="• $>gaF2/—|C$SMb&=#4."6
3/g
K.{.6†^VeO
:,?@.+@BC+@//4%*g;<=,fˆ™.6
<=,u=b
¢Sˆ.uf/.(
Kd>K5>K5KcHcb,e
tSu>+9"#$1g…19 f u£V.…
t¢S¤….2%cC<$9 •f u£:
…t¢S¤
!"#$#%&
+0<ˆ$SC9B %{|C C $>gaF2Cv
*C"01+|"6, •&nb>=+.ˆ%N26Cnbu
1b/';$>gaF2:,?@.+@BC+@//6=,b>
=‹"7$9s=Cn(
• 9A>£+b&¤(^n6=,b£.¥§¤=6|.=8%@=
/b0C"0f%a
• :9>>A>9A;£/<b¤(6=,b%…$&S%,6
=,=&&%8"0=,CnCNa•™.£C.+/@+¤ ?@.+
ABC+@//)<bf+*"&/+v b%S&£y.+¤ˆ
n=+{ˆu=ˆ…Cˆ%#b&ˆ"6 M%#b>b
Ya;=,+@.+@BC+@///.(
²£ž+=³³)$P@³I.@¤(
?@.+@BC+@//62/—b0C"0$1gf6=6f
62 6 =, 6 =0 $‘%n "0 šž+=œ … šœ … •
š)$P@œ…šI.@œ£I1²™.6$‘%n6=0¤f62bM
| $d 1 . 1= £(¤
I1f$,C.+/@+ ?A$Mf=6$.%.+2!=C9$‘
%n$d=,6=0 •šž+=œˆšœˆ6•@+.ˆ"6•
=@..+.@+š£šˆš¤œˆ"6š³œ%*v%>Su=@+."6$M$1
g•.‰6”C9b0CI1²”6=@..+.@+ˆu
$M6bd%n6I%uˆ|.%‰6/.%N2(
²£ž+=³³)$P@³I.@¤(
/.(šb0C$1gf6$‘%n$d=,6=0@
/.$d$1gf@+.(ž+=ˆˆ)$P@"6I.@+s@/.$d
1.1=œ
' ()*+",-#!.#
)<b ´™.
^S&b$1bŸ+HbB8Rµ
g e•/8CCN£¤
K.{.6†^VeO
ge eb3C9•/8£¥¤
g; ey@/C.@£b9+‘ˆ.$¤
gC e¥y@/C.@
gZ ey+£s==‹ˆ•/8ˆ"61S0¤
gh e¥y+
f t‘%n=,f…R
g, t‘%n=,f
i eM|=,f…R
gj eM|=,f
k 7 $>gu>/+vˆ"a;³t³
tt/—/+v"0ˆtˆ…tt£ $>g
%*/+vH+ /.¤
l>1m )+v"0=,+ b+u=ˆ"a;¶$·/—
/+v"0ˆ$ˆ…
lf>1m )+v"0$1gb6b3, b+
u=ˆ"a;¶²$·/—b3/+v"0ˆ$ˆ+
/+v"0tˆžˆ“
l>njm )+v"0$1bŸb6,b962ˆ"a;¶¥·
/—/+v"0ˆtˆ…
^_ G %{=,$>g/.u%*B@==,
2M8%¡%8"0 2M8%*+!$62+$9
62
o G %{u=,…b3ub…$>g
%g+0uˆ"a;›t/+v"0tˆtˆb3
/+v"0t
p G %{b3u…u#b…$>g
%g+0uˆ"a;¸t/+v"0tˆtˆtˆtˆ
“
q G %{u=,…u#b…$>g
%g+0uˆ"a;¹t/+v"0tˆtˆtˆ“
b3/+v"0t
rs G %{u%|b…$>g%g+0uˆ
"a;º»Œ/+v"0
rKs G %{ua1b…$>g%g+0
uˆ"a;ºˆ»/+v"0ˆˆˆ“
K.{.6†^VeO
b3/+v"0
rK:s G %{uH%M=b%g+0uˆ"a;ºˆ»
/+v"0ˆˆ"6b3/+v"0
…
()%/0&)1$#%&
A1C=, MC0%8*"#"&/b0Cf
"6.2M@?@.+ABC+@//)2/@=@B?@.+ABC+@//6
.=@/C.@+<"& 0Cª A<F.%M19
%8*‘#"0?@.+ABC+@//
$#
0C?@@B*++@.+@BC+@//$1$1{
£+@.¥2¤u”g.=,Cg™£/.¤C¦C|
./';•0C+@Bb =6bŽbdS%8*b
Ya;(
string pattern= “<H2 class=Lead>” ;
Regex myRegex= new Regex(pattern);
6Cn 0C?@@B(
(<"
K&'(+9"#•=;‰%*+.F./++?@@B
L&M?N(+{$M&B@=+@.+@BC+@//R!=HC9
F.+ .2b3
t&'#%
?&8 ;?'( +9 "#=9 s= 6 < u= *= %8 "0
?@.+ABC+@//
?&88;6?'(+9"#=9s=6/8u=*=g
"0<u=+<=9
&8 ;?O&;8;6?(%12<u=g"0/8u=%*
b.$
'H (+9"#+{$$M&B@=?Au!=12=,/b0C.2
b3+<C.@+
H (R!=+<C.@+B@=uB1&=,?A.2b3+s+9"#
bMF9aB 6=,%8*:.21
H ?'(R!=+<C.@+B@=19 B1& =,?Au.2
b3+s+9"#19•/b0C63B@=:.%*‰
#n
K.{.6†^VeO
L?" ?(.2M•B1& =,C.@+%*%{™.
$d=,?A$d=,fb.2M%*Œ%{
"(¡=,C.@+6=,=9s=•fd•"{
+a%*Œ%{$d=,/b0C+<?A
P?' ?(@/.C@$1g•b6%*@/.C@+<C.@+
23
0C62*+•bMF921 =, ";/
b0C£=.¤?@.+ABC+@//).%N2=!u"a;Ž/';
Cg:. 0C?@@B%>+9"#%8*b>:.%>u
>!=+./b0C%n<+<fC
)';,a:.@// 0C:.$ $M&
B@=%Š!=+./b0C.2.
Ya;(
string chuoi = "123abcd456bdabc";
string pattern = "abc";
Regex myRegex = new Regex(pattern);
Match m = myRegex.Match(chuoi);
if (m.Success)
{
Console.WriteLine("Tim thay
chuoi con {0} o vi tri thu {1} trong chuoi",
m.Value, m.Index);
}
Else
{
Console.WriteLine("Khong tim thay chi ca");
}
eMF9(
Tim thay chuoi con abc o vi tri thu 3 trong chuoi
Lp MatchCollection
0C62*+S•/b0C63%•s<
.S6=,C*C$1$1{"60C62b3uC
g bd S • %8 * :.@ /— ,
K.{.6†^VeO
ab9#98>9; 0C?@@B+9"#V.2:.@6=9
%8*:.6%*
Ya;(
static void Main(string[] args)
{
MatchCollection mc;
string chuoi = "I like money, like woman and like
C#";
string pattern = "like";
Regex myRegex = new Regex(pattern);
mc = myRegex.Matches(chuoi);
foreach (Match m in mc)
{
Console.WriteLine("Chuoi con '{0}' xuat
hien o chi muc {1}", m.Value, m.Index);
}
}
Kt qu tr v:
Chuoi con 'like'xuat hien o chi muc 2
Chuoi con 'like'xuat hien o chi muc 14
Chuoi con 'like'xuat hien o chi muc 29
C3 #b9#98>9;4
V.,a %8*:.6(
$8I#
Q2+ ?&8R
G¦"a;(
static void Main(string[] args)
{
MatchCollection mc;
string chuoi = "This is a example string.";
string pattern = @"\S+\s";
Regex myRegex = new Regex(pattern);
mc = myRegex.Matches(chuoi);
for (int i = 0; i < mc.Count; i++)
{
Console.WriteLine("The match[{0}]: '{1}' co chieu
dai la {2}", i,mc[i].Value, mc[i].Length);
K.{.6†^VeO
}
}
fµ)%!=•bb3C9b9+‘ˆ"61¹$M
=,…#bd% /.Rµ/$M6b9+‘I%uˆ
,CS.u=&%#šŠ2%!=$1gb¥y@/C.@@/.$d
y@/C.@œ
eMF9 "a;+<6(
The match[0]: 'This ' co chieu dai la 5
The match[1]: 'is ' co chieu dai la 3
The match[2]: 'a ' co chieu dai la 2
The match[3]: 'example ' co chieu dai la 8
Lp Group
^3b4.6+1&b,CS•$>g/
b0C"0."2$Su>CNa•™.•%S
fb0C
Ya;ˆu>$S=8/b0C.+<%{.ŒLK"6,CS19
LK!=12%*$1g6+<%Sf
0C+CC¦C$SS•u=/b0C.+<|C C
?@.+ABC+@//ˆ"6*+bMF9H$>g,Cu=
21
:,$>g,Cu=%…<=,u="61C?@.+
ABC+@//¯$1gf6b0C"0?@.+ABC+@///—%*
%."6u=Ya;ˆ=8Su=LKˆ$Su>"M=,?@.+
ABC+@//$M=,…#.2@/.$d/C.@
/.(
¼œ£›£µ³µ¤¹¤µ/œ
0C:.%*‹B1H+Cˆ"6u=,C*C=.<
+C/g.19 u==6:.!=12
0C+C*+•bMF9S%*H
*=u=21Ya+Cu>*=Dˆ…#f•
+=,n/b0C21ˆug.=,C*Cs=•%8
* .C+@Y!+CbMH.H.C+@ˆ/$/+${*=u
>%*+2B1+MC
> & +C /— %* +9 "# $d , a
:.+C/£/8+C¤…:.+C/£š<+Cœ¤UDAI
#<J\:
K.{.6†^VeO
u^ov#AJ>:9w_x!&7y#!U
Ya;/.%N2/';bM+|,Cu=s.%>*=
•f,C6u=(
static void Main(string[] args)
{
string pattern = "(a(b))c";
string chuoi = "abbabc";
Regex myRegex = new Regex(pattern);
Match m = myRegex.Match(chuoi);
for (int i = 0; m.Groups[i].Value != ""; i++)
{
Console.WriteLine("{0} co chieu dai
{1}", m.Groups[i].Value,
m.Groups[i].Length);
}
}
eMF9(
abc co chieu dai 3
ab co chieu dai 2
b co chieu dai 1
^S=Š/.%N2/';bM+|,Cu=u=.<£.=@"6
".@¤%>*=•/$/+/H=,fg.•&+<
SgšI:A(YAœ=6?A${¡dN1.1=£(¤
static void Main(string[] args)
{
Regex myRegex = new Regex(pattern);
Match m = myRegex.Match("Section:119900");
for (int i = 0; m.Groups[i].Value != ""; i++)
{
Console.WriteLine("{0} co chieu dai
{1}", m.Groups[i].Value, m.Groups[i].Length);
}
}
eMF9(
Section:119900 co chieu dai 14
Section co chieu dai 7
119900 co chieu dai 6
2&(&%%&
60C*+C*Cs=6•u=%*
*="6+9"#=,3•u=%**=+=,n/b0C
21@62,S+@.¥2"6b3uCg
bdS >& 0C+C@%*+9"#+C*C
=6,a:.+C/+9"#
K.{.6†^VeO
Ya;(IR!="6+./8•u=%**=$d=,
?@.+ABC+@//6=M6%>+aH*=+<+—+<=f
6"< =3+C@
static void Main(string[] args)
{
Regex myRegex = new Regex("(a(b))c");
Match m = myRegex.Match("abbabc");
Console.WriteLine("So nhom duoc tim thay la:
{0}",m.Groups.Count);
}
eMF9(
So nhom duoc tim thay la 3
2(
0C62g.•bMF9H=,*=21.+<=,
@BC+@//¥£/$¥@BC+@//¤
2((&%%&
:fn=,%8*?@@Bb0C"0=,/$@BC+@//ˆ=,>
&.C+@/—%*S+.ˆ"6%*<="6C*C.C+@@
:f%8*.C+@*+=,*=£.C+@¤%¡
:fu=/—u+<=!=,.C+@@•=;b0C
"0/$@BC+@//%*‘#"0u=
0C.C+@@*+=,S•f
%**="6+9"#=,3•*=%*&ŒF.
=,u=*=21,a.C+@/ˆ=,%8* 0C
.C+@@ˆ%*1C6=,6"< 0C
:."6+C|C+2B163 f%**=
Ya;/.%N23v%M+@.+@BC+@//£$¤¹%>!=+.=,
…#/b0C+<fšG\¨$$$G\¨$$œ
static void Main(string[] args)
{
string chuoi =
"XYZAbcAbcAbcXYZAbcAb";
string pattern = "(Abc)+";
Regex myRegex = new
Regex(pattern);
Match m = myRegex.Match(chuoi);
GroupCollection gc = m.Groups;
CaptureCollection cc;
Console.WriteLine("So nhom thu
luom duoc = {0}",gc.Count.ToString());
Console.WriteLine();
K.{.6†^VeO
for(int i=0;i<gc.Count;i++)
{
cc = gc[i].Captures;
Console.WriteLine("So capture = " +
cc.Count.ToString());
for(int j=0;j< cc.Count;j++)
{
Console.WriteLine(cc[j] + " bat dau tu
ky tu " + cc[j].Index);
}
Console.WriteLine();
}
}
e<F9
So nhom thu luom duoc = 2
So capture = 1
AbcAbcAbc bat dau tu ky tu 3
So capture = 3
Abc bat dau tu ky tu 3
Abc bat dau tu ky tu 6
Abc bat dau tu ky tu 9
45)&6!7##%&&#)#8#9%:
;
?@.+@BC+@//6=,Cn 3•C+!"6 "&%>
S%,"6C +>).%N26b.$ /';+@.+@BC+@//
+3•06«."."6±(
Y03•«.".(
using java.util.regex;
Y03•±(
using System.Text.RegularExpressions;
Y0•"&%Šb.$ /';|.u>&•
3"&34 +@.+@BC+@//!=bM="6.2M
$ BN2•|C C%…$&
' 9#8#7%<1150=>
3;%*0&+Cn62/—|C|.BN2ˆ
b>=+.fˆb>=+.|C C"6•3C9sf+*|.
C+!8tS<b>=+.$>gaF2 =!BN2
+•3;62%>b>=+.%,aB $>g%u
K.{.6†^VeO
$#?!!
?@@B$26=,3;%n2%- a71&.2%>SCˆ
b>=+."6 $>gaF2uu$,$>gaF2
•3•C+!b .(Aˆ«.".ˆ“Y6C¦C
2>%c$>gaF2•. 3•C+!
?@@Bt2 %*M bM$d «.2".@+/ £6=, 2< ."#
?@.+ABC+@//¤
?@@Bt2/—%,3/ •CnCv*C"0$>ga
F2 $Sˆ"63$ •fB1&+$>gaF2
£M u¤ ). %N2 6 =, "6 $ 4 .2 /' ; +
?@@Bt2(
• M'S""(>{=,./ 19 fCv*C"0$>g
aF2
K.{.6†^VeO
• L?" ?( =dCa.+< =6!ug7!=bM="6.2
Mf%*C"6+@B$B"0$>gaF2
• "()' $>gaF2$ +<6
b@/dd•=6%8* $S%*!=12$ /'
;$>gaF2 $S
• b$1bŸ$6"6.‰C.@=..2%>
?@@Bt2>{bMF9=, %,"6%s$,b$S.2
%c$1g!+$>gaF2
• &.68&(%.$>gaF2%*S"6C$.+%>$S
"6/+@@ =!
?@@Bt2u>S2+<•y/OQˆ:AˆDDDˆGKˆY/..
•y/ E R u > S2 8 +< =3 +4 ( :y.+@ˆ
K.+.@/ˆ+//J"@+J½½@
$#@%
?@@BK.6=,+!b>=+.$>gaF2@%*S$d
9)@"@@".tSŒNn=,+!2&y@$&%S"6=,
%4+2#@+@6u>/';u?@@BK.%*"M66
$ «.".)+Cˆ%uuŒf+*3•«."./)+C
?@@BK./—%,3=6 fCv*C"0f$>ga
F2%*Cd3Ca.+<M$SC=,|C C/.!?@@BK.
/—3/ •Cn/.%u?@@BK.63;34/';b
"M +!+<@%>b>=+.$>gaF2 =!
3A1<8#7*050=> &%*)
^>S=,3;b>=+.$>gaF2@6=,%#b3
F buM$Su=,bMg"#C +>y@$"6•bMg
"#+@.+@BC+@//nM!$Su>S=!=,+.
K.{.6†^VeO
?@@BK.b>+<Y6u6+7=4%Š6=/–u$S).
%N26=,/8+.%>!(
TUU??,)" '&" 4&4)&;UTVf+*KVKK?AˆKVKKJ)LG"6«.".)+C
TUU>>>)??,)&;U(f+* 3•A%*C +>$dI."
)@+2.@
K.{.6†^VeO
TUU>>>)868" )&;U(%*BN2$d 9:@."
TUU>>>);.??,)&;(6=,«."..CC@S2+<+!2&y@$£2<
n6%…«.".+!2&¤+.62/';"&P.".+@@B%>f
+*I%u•$>gaF2%*Sd+.6266Cv*C
"0«.".
K.{.6†^VeO
z(.:NY{
G:6=,3•%*g;+1#+C+!ˆB'•
&”+2#93+0%N2"&. "6S+. 6
&G:3F.IJ:G:KL+@+16R"6+‘+8Y!
M%>b‘C;%#62ˆ:+/½%Š+.%4Lv"0L
G:KL
z(|e}{,t!U+{,t
Ya;%>S=,6&G:%9/.
5#8:(
<Blog>
<Title>YinYang's Programming Blog</Title>
<Author>
<FirstName>Yin</FirstName>
<LastName>Yang</LastName>
</Author>
<Categories>
<Category>LINQ</Category>
<Category>WPF</Category>
<Category>ADO.NET</Category>
</Categories>
</Blog>
)'; ”"0IJ:G:KL£.=@/C.@)2/@=G=¤(
XmlDocument doc = newXmlDocument();
XmlElement blog = doc.CreateElement("Blog");
K.{.6†^VeO