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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:52:21+00:00 2026-05-11T01:52:21+00:00

I have two strings: the first’s value is catdog and the second’s is got.

  • 0

I have two strings: the first’s value is ‘catdog’ and the second’s is ‘got’.

I’m trying to find a regex that tells me if the letters for ‘got’ are in ‘catdog’. I’m particularly looking to avoid the case where there are duplicate letters. For example, I know ‘got’ is a match, however ‘gott’ is not a match because there are not two ‘t’ in ‘catdog’.

EDIT:

Based on Adam’s response below this is the C# code I got to work in my solution. Thanks to all those that responded.

Note: I had to convert the char to int and subtract 97 to get the appropriate index for the array. In my case the letters are always lower case.

    private bool CompareParts(string a, string b)     {          int[] count1 = new int[26];         int[] count2 = new int[26];          foreach (var item in a.ToCharArray())             count1[(int)item - 97]++;          foreach (var item in b.ToCharArray())             count2[(int)item - 97]++;          for (int i = 0; i < count1.Length; i++)             if(count2[i] > count1[i])                 return false;          return true;     } 
  • 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. 2026-05-11T01:52:22+00:00Added an answer on May 11, 2026 at 1:52 am

    You’re using the wrong tool for the job. This is not something regular expressions are capable of handling easily. Fortunately, it’s relatively easy to do this without regular expressions. You just count up the number of occurrences of each letter within both strings, and compare the counts between the two strings – if for each letter of the alphabet, the count in the first string is at least as large as the count in the second string, then your criteria are satisfied. Since you didn’t specify a language, here’s an answer in pseudocode that should be easily translatable into your language:

    bool containsParts(string1, string2) {     count1 = array of 26 0's     count2 = array of 26 0's      // Note: be sure to check for an ignore non-alphabetic characters,     // and do case conversion if you want to do it case-insensitively     for each character c in string1:         count1[c]++     for each character c in string2:         count2[c]++      for each character c in 'a'...'z':         if count1[c] < count2[c]:             return false      return true } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer $('#Row1').after($('#Row2')); will work May 11, 2026 at 11:08 am
  • added an answer alt text http://img19.imageshack.us/img19/8724/picture4asx.png if you click on untitled.m it will… May 11, 2026 at 11:08 am
  • added an answer In case the program was uninstalled using Microsoft Installer you… May 11, 2026 at 11:08 am

Related Questions

I have two strings: the first's value is catdog and the second's is got.
I have two String.printable mysteries in the one question. First, in Python 2.6: >>>
I have two strings and would like to display the difference between them. For
I have two strings and I would like to mix the characters from each
Suppose I have the following two strings containing regular expressions. How do I coalesce
If I have two variables: Object obj; String methodName = getName; Without knowing the
I have two strings <EM>is <i>love</i></EM>,<PARTITION /> and <EM>is <i>love</i>,<PARTITION /> I want a
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
I have a function which parses one string into two strings. In C# I
I have a two-dimensional array (of Strings) which make up my data table (of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.