Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 10th, 2006, 5:00 AM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 154
Rep Power: 3 programmingnoob is on a distinguished road
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?
programmingnoob is offline   Reply With Quote
Old Nov 10th, 2006, 7:39 AM   #2
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 214
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
Not sure what type of syntax that is. In perl I'd do something like
^a[bc]*[a(ac)] haven't tested it
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Old Nov 10th, 2006, 9:17 AM   #3
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
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
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Nov 10th, 2006, 9:22 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
kodos is good, it what i use to help me figure out my regular expressions.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Nov 10th, 2006, 12:52 PM   #5
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3 Jimbo is on a distinguished road
Since you are specifying the end as well, I'll just borrow Dizzutch's for a sec:
^a[bc]*(a|ac)$
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Regular Expression King C# 2 Apr 30th, 2006 9:41 PM
Word Frequency Regular Expression hoffmandirt C# 4 Feb 27th, 2006 8:21 PM
Problem with regular expression? wingz198 Perl 3 Jan 24th, 2006 5:49 PM
Regular Expression toghian C++ 12 Dec 28th, 2005 10:12 PM
Regular Expression HELP -- thanks paulchwd JavaScript and Client-Side Browser Scripting 3 Oct 11th, 2005 4:40 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:32 AM.

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