Sign in to follow this  
Followers 0
nullschritt

Searching for a string in any order?

4 posts in this topic

I was wondering if it is possible (preferably with regex) to search for a string in any order.

So for example the string 101 would search for 011, 110, 101.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes, well kind of. Using regexp with "[abc]+" will match b ab bac bbbbbbbbbbbbbbbbbb accc. An exact match with the same number of characters is going to involve some additional steps. Interesting to think about. Regexp might not be the best way to approach this. If you search for anagram you might find some scripts which will help you.

BTW this is the wrong forum. Ask to have this topic moved to Help and Support.

Edited by czardas

Share this post


Link to post
Share on other sites

An example.

#include <Array.au3>

Local $sTestString = "1001001101010101011010100"
Local $sString = "101"

;------------ Create Reg Exp Pattern ----------------
Local $aArray = StringSplit($sString, "", 2)
Local $aNewArray = _ArrayPermute($aArray, "")
$aNewArray = _ArrayUnique($aNewArray, 1, 1, 0, 0)
;_ArrayDisplay($aNewArray, "Array Permuted")
Local $sRegExpPattern = "(" & _ArrayToString($aNewArray, "|") & ")"
ConsoleWrite($sRegExpPattern & @LF)
;---------> End of Create Reg Exp Pattern ------------

Local $aResults = StringRegExp($sTestString, $sRegExpPattern, 3)
_ArrayDisplay($aResults)
1 person likes this

Share this post


Link to post
Share on other sites

Oh crap, looks liek I posted asking for help in example scripts. My bad guys, had a total brain fart...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0