#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Regular expression to find if a string contains all the characters of another string


    Hi

    I need a regular expression to find if a string contains all the characters of another string.

    Can anyone help me with this please?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Worked Out The Answer !


    Originally Posted by rssadiq
    Hi

    I need a regular expression to find if a string contains all the characters of another string.

    Can anyone help me with this please?
    HERE IS THE ANSWER:

    REPEAT .*[a,b,c]{1} as many times as the number of characters in the 2nd string and replace [a,b,c] in the square bracket with all characters in the 2nd string too.
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,002
    Rep Power
    9398
    Which is a horrible, horrible application of regular expressions, but hey! more power to you.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep Power
    0
    Originally Posted by rssadiq
    REPEAT .*[abc]{1} as many times as the number of characters in the 2nd string
    Unfortunately, it will match "a" repeated three times with no "b" or "c" in the string.

    Code:
    .*[abc].*[abc].*[abc]
    
    matches not only "abc" and "cba"
    
    but also "aaa"
    The correct solution is outlined on my page. But I agree with requinix that it's a terrible application of regular expressions. You should write some code instead; any programming language allows you to check the characters in a loop.

IMN logo majestic logo threadwatch logo seochat tools logo