Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1037175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:49:20+00:00 2026-05-16T14:49:20+00:00

I am having trouble building a regular expression with the set of strings over

  • 0

I am having trouble building a regular expression with the set of strings over {a, b, c} that is an odd length with exactly one a. Here is my best attempt so far:

(bb|bc|cb|cc)*a(bb|bc|cb|cc)*

This does good for even b and c on either side of the a, but does not account for a odd b and c combination on either side of the a.

Any hints?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:49:20+00:00Added an answer on May 16, 2026 at 2:49 pm

    Your string will be a prefix followed by a followed by a suffix.

    Both prefix and suffix can be zero length. If not, they have to be either both even or both uneven. This means you have two main cases.

    EVENPREFIX a EVENSUFFIX | UNEVENPREFIX a UNEVENSUFFIX
    

    Try this (incomplete and wrong):

    ([bc][bc])*a([bc][bc])*|([bc][bc][bc])*a([bc][bc][bc])*
    

    There is still one uneven case missing: a single [bc]:

    (([bc][bc])*a([bc][bc])*)|([bc]([bc][bc])*a[bc]([bc][bc])*)
    

    According to http://www.fileformat.info/tool/regex.htm, this matches

    • a
    • cac
    • ccabb

    I expect it matches the rest too…

    The left side guarantees even (or empty) sequences of b or c.
    The right side is either a single b or c followed by a multiple of two (so that it stays uneven).

    Kobi came up with this refinement of the above:

    ([bc][bc])*(a|[bc]a[bc])([bc][bc])*
    

    How does this work?

    The first group is guaranteed to be even. The second group is guaranteed to be uneven with a single a inside. The third group is guaranteed to be be even. Thus, the whole is guaranteed to be uneven.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble building a regular expression because I'm really a noob to the
I'm building a sample app for practice and am having trouble determining the best
I am having trouble building a Python function that launches TkInter objects, with commands
My system is having trouble building the boost libraries. I understand that most boost
I'm having trouble building a simple c++ program that tests out regex's from the
I'm having trouble building a little program that uses Boost.Test on my Mac with
I am building a database system and having trouble with the design of one
Having trouble getting one portion of my code to work. Building a rudimentary linked
I'm having trouble building a connection string that my VB6 program can use to
I'm having trouble building a bit of jquery that grabs a selector that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.