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 3320586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:57:39+00:00 2026-05-17T22:57:39+00:00

can you help me with this: I want a regular expression for my Ruby

  • 0

can you help me with this:

I want a regular expression for my Ruby program to match a word with the below pattern

Pattern has

  1. List of letters ( For example. ABCC => 1 A, 1 B, 2 C )
  2. N Wild Card Charaters ( N can be 0 or 1 or 2)
  3. A fixed word (for example “XY”).

Rules:

  1. Regarding the List of letters, it should match words with

    a. 0 or 1 A

    b. 0 or 1 B

    c. 0 or 1 or 2 C

  2. Based on the value of N, there can be 0 or 1 or 2 wild chars
  3. Fixed word is always in the order it is given.
  4. The combination of all these can be in any order and should match words like below

ABWXY ( if wild char = 1)

BAXY

CXYCB

But not words with 2 A’s or 2 B’s

I am using the pattern like ^[ABCC]*.XY$

But it looks for words with more than 1 A, or 1 B or 2 C’s and also looks for words which end with XY, I want all words which have XY in any place and letters and wild chars in any postion.

  • 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-17T22:57:40+00:00Added an answer on May 17, 2026 at 10:57 pm

    I consider myself to be fairly good with regular expressions and I can’t think of a way to do what you’re asking. Regular expressions look for patterns and what you seem to want is quite a few different patterns. It might be more appropriate to in your case to write a function which splits the string into characters and count what you have so you can satisfy your criteria.

    Just to give an example of your problem, a regex like /[abc]/ will match every single occurrence of a, b and c regardless of how many times those letters appear in the string. You can try /c{1,2}/ and it will match “c”, “cc”, and “ccc”. It matches the last case because you have a pattern of 1 c and 2 c’s in “ccc”.

    One thing I have found invaluable when developing and debugging regular expressions is rubular.com. Try some examples and I think you’ll see what you’re up against.

    I don’t know if this is really any help but it might help you choose a direction.

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

Sidebar

Related Questions

I'm trying to write a regular expression in PHP. From this code I want
I'm trying to construct a regular expression that would match a pattern as such:
I have this regular expression to help me validate a form input. var nrExp
I can use Alternation in a regular expression to match any occurance of cat
I hope there's a SharePoint expert here on SO who can help with this.
Wondering if anyone can help me with this annoying but trivial (in terms of
What are the problems that calling this method can help with? Do you ever
As a follow-up to this question I am hoping someone can help with the
Ok, this is bit of an obscure question, but hopefully someone can help me
Can someone help me identify what the purpose of this unidentified syntax is. It

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.