RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Permutations of a character series
Expression
(?!.*([abcde]).*\1)^[abcde]{5}$
Description
Let's say that you have a series of characters "abcde" and you want to match all strings that could be comprised of those characters with each character used exactly once. This could loosely be termed an anagram matcher, although if the string contains duplicate letters it would require modification of this pattern. In the example case we have a string "abcde" and we want to match any permutation of "abcde". Note that the "5" used in the pattern indicates the number of characters specified in the character set "abcde", "5" would still be used if "abcde" would be replaced with "a-e" since there would still be 5 characters in the series. If you are curious about how to require duplicates in the pattern (to match all permutations of "apple" for example) I would use (?=^.*p.*p$)(?!.*([ale]).*\1)^[aple]{5}$
Matches
abcde | dbcae | edcba
Non-Matches
abcbe
Author Rating: The rating for this expression. Doug Drudik
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials