Regex - pairs verification

0 views
Skip to first unread message

Bruce

unread,
Jun 13, 2009, 11:15:25 PM6/13/09
to Regex
Hi
I have a basic regex question.

^(([ab],)([ab],))+$

This makes sure {a,b,} and {a,b,a,b,} are matched, but {a,b,c,} is
not. (only pairs)
Now, I want to extend this for any string and not just a and b. So, I
modify the above regex to

^((.*,)(.*,))+$

But it no longer matches only pairs. {ae,bee,} is matched but
{ae,bee,aer,} is also matched! I just don't understand why. What I am
missing here? I am using C#.

Thanks
Bruce

Sanket Pathre

unread,
Jun 17, 2009, 1:21:15 AM6/17/09
to re...@googlegroups.com
try this one
^(\w,\w,?)+$
will match any pairs like 
1> a,b
2> a,b,c,d

wont macth
1> a,
2> a,b,c
--
(¨`·.·´¨) Always
 `·.¸(¨`·.·´¨) Keep
(¨`·.·´¨)¸.·´ Smiling!
 `·.¸.·´

Sanket Pathre
Junior Trainee engineer
Akstech Pvt, Ltd.(Vashi)
Reply all
Reply to author
Forward
0 new messages