473,513 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex: select all possible of a pattern

dlite922
1,584 Recognized Expert Top Contributor
I'm putting this question in perl forum be we don't have a regex forum (we should) and 2, you guys rock at Regex.

I'm trying to find all patterns of a number to accommodate a dyslexic typer. By matching any pattern that contains the characters in the given input as many times as they /exist/ in the input. English sucks, example's better:

given 231

match 2 3 and 1 in any order, but do not repeat because there's only a single 1, a single 2, and a single 3:

123
132
213
231
312
321

but not:
111
112
221
222
311
333
223
332
etc...

My brain is locked. I'm thinking it should be easy but all i can come up with is along the lines of:
Expand|Select|Wrap|Line Numbers
  1.  (3|2|1)+ 
which of course matches ALL of the above unwanted outputs.


Thanks,



Dan
Aug 12 '09 #1
2 2167
nithinpes
410 Recognized Expert Contributor
You can try this:
Expand|Select|Wrap|Line Numbers
  1. /^(\d)(?!\1)(\d)(?!\1)(?!\2)\d$/
  2.  
The negative lookahead assertion(?!) checks that the character that follows does not match the pattern mentioned inside the cluster.
Aug 13 '09 #2
dlite922
1,584 Recognized Expert Top Contributor
Thanks, ! suck at neg lookaheads.

I did change the \d to [123] though, because my character set must be those. Otherwise 456 would get through also.

Expand|Select|Wrap|Line Numbers
  1. ^([123])(?!\1)([123])(?!\1)(?!\2)[123]$

Dan
Aug 13 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9704
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
20
8027
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
3
8233
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&") Regex.Replace(Subject, "\'", "'") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&|'}")...
8
1810
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
9
2791
by: taylorjonl | last post by:
I am having a problem matching some text. It is a very simple pattern but it doesn't seem to work. Here goes. <td*>.*?</td> That is the pattern, it should match any <td></td> pair. Here is...
16
2229
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
2042
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title ...
2
1533
by: John B | last post by:
I am trying to do a pretty simple pattern match using regex. The pattern is ^(?:(?<Item>.*?)@:@)*$. This should return a match for test123@:@ but does not, instead it never returns when I call...
3
1290
by: =?Utf-8?B?bWFnZ2ll?= | last post by:
hi, I've been working getting a file parsed out using Regex. There's something I don't understand. When I define the pattern for my fields in my file, I am telling regex to grab those fields (...
0
1529
by: vmysore | last post by:
I am trying to get all the columns selected within a SQL query (including the sub selects). When the code hits matcher.find(). i get the following exception: Exception in thread "main"...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.