|
|
unknown order
-
06-12-2007, 6:56 AM |
-
XYZ
-
-
-
Joined on 06-12-2007
-
-
Posts 1
-
-
|
How do I match any sequence of known characters (a, b ,c and d for example) in any order without explicitly specifying all combinations? For example I want to match: abcd, dcab, abdc, bcda, etc. Thanks.
|
|
-
06-12-2007, 8:26 AM |
-
docdawson
-
-
-
Joined on 03-13-2007
-
-
Posts 155
-
-
|
I think its again the "cats and dogs" problem but I can`t find the thread anymore: But I got the regex in my "important-regex" text file  so your regex should look like this if nobody finds an easier way or shows that this one fails on some data.
^(?=.*?a)(?=.*?b)(?=.*?c)(?=.*?d).*?$
|
|
-
06-12-2007, 8:30 AM |
-
Sergei Z
-
-
-
Joined on 07-20-2005
-
Miami, Fl USA
-
Posts 2,553
-
-
|
for that u use a character class, which consists of 4 characters: [abcd] next u specify the length of the match pattern u r looking for: length=4: {4} thus arriving at the pattern u'd want ot use: ^[abcd]{4}$ it'll match on abcd, dcab, abdc, bcda, etc. note ^ and $ here: the start and the end of the line/input, meaning that in this scenario u will be matching your strings one-at-a-time, on a separate line OR in a text box where it sits alone. IF u want ot match your strings in a piece of text, i.e. as parts of a bigger text, then startegy will have to be changed. Usually it will get more involved.
|
|
-
06-12-2007, 8:37 AM |
-
Sergei Z
-
-
-
Joined on 07-20-2005
-
Miami, Fl USA
-
Posts 2,553
-
-
|
docdawson: I think its again the "cats and dogs" problem but I can`t find the thread anymore: But I got the regex in my "important-regex" text file  so your regex should look like this if nobody finds an easier way or shows that this one fails on some data.
^(?=.*?a)(?=.*?b)(?=.*?c)(?=.*?d).*?$
hi, docdowson, i think u misinterpreted the task. The poster is looking for combinations of 4 characters. Your regex will match on any combination of characters including four mandatory ones: a, b,c,d, i.e your regex 'll match on say aXbZcSdZ which does not comply with the original spec
|
|
-
-
06-12-2007, 10:39 AM |
-
mash
-
-
-
Joined on 04-14-2005
-
Birmingham, AL
-
Posts 1,531
-
-
|
Eh, what's up doc?  Here's a pattern that should match http://regexlib.com/REDetails.aspx?regexp_id=564 This question has come up before in the last few years. In fact I'm pretty sure Sergei came up with an alternate solution to my version that in this forum somewhere. The only issue is the regex grows very fast for each new letter you add
Michael "In theory, theory and practice are the same. In practice, they are not." Albert Einstein
|
|
-
06-12-2007, 10:49 AM |
-
Sergei Z
-
-
-
Joined on 07-20-2005
-
Miami, Fl USA
-
Posts 2,553
-
-
|
u r right: i overlooked the req that all 4 chars are mandatory in the string. we can do it by adding 4 look-aheads: (?im)^(?=.*a)(?=.*b)(?=.*c)(?=.*d)[abcd]{4}$ now aaaa will not be matched.
|
|
-
06-12-2007, 6:14 PM |
-
-
06-12-2007, 9:37 PM |
-
ddrudik
-
-
-
Joined on 05-24-2007
-
USA
-
Posts 1,540
-
-
|
That's actually what I suspected, so I tried: ^(?=.*a)(?=.*b)(?=.*c)(?=.*d)[abcd]{4}$
But with: Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True regEx.MultiLine = True teststring = "abcd" regEx.Pattern = "^(?=.*a)(?=.*b)(?=.*c)(?=.*d)[abcd]{4}$" Set Test = regEx.Test(teststring)
Test is False. I suspect that VBSCRIPT does not support suffix (or prefix) exclusion matching (or matching if not present). That's something that hasn't worked for me in the past so I am curious if there's a change I can make to get it to work.
|
|
-
-
06-12-2007, 10:22 PM |
-
06-13-2007, 1:58 AM |
-
docdawson
-
-
-
Joined on 03-13-2007
-
-
Posts 155
-
-
|
mash:Eh, what's up doc?  Here's a pattern that should match http://regexlib.com/REDetails.aspx?regexp_id=564 This question has come up before in the last few years. In fact I'm pretty sure Sergei came up with an alternate solution to my version that in this forum somewhere. The only issue is the regex grows very fast for each new letter you add
Hi mash, I rarely search in this database. My fault again . But good to know that this is an solution because I tried (sadly without success) this way too. And thats another sign for me that I`m just at the beginning of being able to create good and solid regex. what is the plural from regex?
|
|
-
06-13-2007, 2:06 AM |
-
mash
-
-
-
Joined on 04-14-2005
-
Birmingham, AL
-
Posts 1,531
-
-
|
ddrudik:It is the leading and trailing lookaround that I was referring to, and from looking at mash's pattern this question was answered back in 2004. It's a good reminder to search for old patterns before asking new questions.
Ah 2004, it was a very good year, for answers to this thread.  Ddrudik, this is the infamous IE lookahead bug http://regexadvice.com/blogs/mash/archive/2004/10/05/320.aspx I found also in 2004. Basically Microsoft's scripting engines don't handle multiple look-aheads correctly. The blog entry has a more detailed explanation.
Michael "In theory, theory and practice are the same. In practice, they are not." Albert Einstein
|
|
-
06-13-2007, 2:19 AM |
-
mash
-
-
-
Joined on 04-14-2005
-
Birmingham, AL
-
Posts 1,531
-
-
|
docdawson: mash:Eh, what's up doc?  Here's a pattern that should match http://regexlib.com/REDetails.aspx?regexp_id=564 This question has come up before in the last few years. In fact I'm pretty sure Sergei came up with an alternate solution to my version that in this forum somewhere. The only issue is the regex grows very fast for each new letter you add
Hi mash, I rarely search in this database. My fault again . But good to know that this is an solution because I tried (sadly without success) this way too. And thats another sign for me that I`m just at the beginning of being able to create good and solid regex. what is the plural from regex?
Don't sweat it Doc, I didn't come up with that solution right away when the question was first asked of me. In fact I didn't think it could be done, the solution just hit me out of the blue months, yes months, later.
Michael "In theory, theory and practice are the same. In practice, they are not." Albert Einstein
|
|
Page 1 of 2 (18 items)
1
|
|
|