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

  • SEARCH
  • Home
  • 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 am having trouble building a Python function that launches TkInter objects, with commands
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
I'm having trouble with global variables in php. I have a $screen var set
I'm building an application in ruby using the sinatra framework and am having trouble
I'm having trouble building gdlib. As far as I can tell, zlib, png and
I'm having trouble building an Entity Framework LINQ query whose select clause contains method
I'm having trouble building a query. I can do what I want in 3
I'm having trouble building the correct regex for my string. What I want to
I'm building an android app and I'm currently having trouble retrieving a bitmap from
I'm building my first ASP.NET MVC application and I am having some troubles with

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.