Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Coder's Corner Lounge (http://www.programmingforums.org/forum11.html)
-   -   regular expression (http://www.programmingforums.org/showthread.php?t=11847)

programmingnoob Nov 10th, 2006 6:00 AM

regular expression
 
so I have to write a reg expression for
the set of strings whose first character is a and ends in either a
or ac. In the middle the strings have any combinations of b's and c's,
including no b's nor c's.

Now, what I came up with is
{a}.{b, c}*.{a, ac}

apparently, this is not right (my solution doesnt match with the answer given) Now, can you tell me what you see wrong in my solution?

Mocker Nov 10th, 2006 8:39 AM

Not sure what type of syntax that is. In perl I'd do something like
^a[bc]*[a(ac)] haven't tested it

Dizzutch Nov 10th, 2006 10:17 AM

in any regex [] creates a grouping of characters to match whereas {} tells the regex how many times to match something
:

[ab]{3}
will match a or b exactly 3 times.
anything in the [] will be matched, so
:

[a(ac)]
will actually match, a, (, a, c, or ). In your case you probable want the following regex
:

^a[bc]*(a|ac)
a good tool to use to test regex on linux is kregexpeditor or kodos, and for windows there a program called The Regulator, which can be found on sourceforge.
If this does not work, please post a couple of examples of strings you need matched for more clarity.
Good luck.

-Dizz

Pizentios Nov 10th, 2006 10:22 AM

kodos is good, it what i use to help me figure out my regular expressions.

Jimbo Nov 10th, 2006 1:52 PM

Since you are specifying the end as well, I'll just borrow Dizzutch's for a sec:
:

^a[bc]*(a|ac)$


All times are GMT -5. The time now is 1:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC