Yoriz Posted July 1, 2009 Share Posted July 1, 2009 (edited) I want to search within a 8 char length string that is made up of 0,1,D or U like the following U011U110 U1UDD110 101U0110 1U11011U The strings i want to find inside are 1011 or 1101 or a single U or D with one or two 1 either side like D11,11U1,11D11. Ive managed to get a kinda what im looking for using the following :- StringRegExp($sString,"(1011)|(1101)|(1{0,2}([uD])1{0,2})",3) Is it possible to improve on this to remove all the blank returns, idealy just return the longest length match which would be be 3 to 5 chars and bias towards showing the longest match if more than one, if no match return nothing. My StringRegExp returns an array of the following. U011U110 [0]| [1]| [2]|U [3]|U [4]| [5]| [6]|11U11 * required match [7]|U U1UDD110 [0]| [1]| [2]|U1 [3]|U [4]| [5]| [6]|U [7]|U [8]| [9]| [10]|D [11]|D [12]| [13]| [14]|D11 *required match [15]|D 101U0110 [0]| [1]| [2]|1U [3]|U * above contains no match required return nothing 1U11011U [0]| [1]| [2]|1U11 * required match [3]|U [4]| [5]| [6]|11U * is a match but above is greater [7]|U Thanks for any help you can give Edited July 1, 2009 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Authenticity Posted July 1, 2009 Share Posted July 1, 2009 #include <Array.au3> Dim $aStr[4] = ['U011U110', 'U1UDD110', '101U0110', '1U11011U'] Dim $sRegEx = '1*[UD]1+|1+[UD]1*|\d{4}' Dim $aMatch For $i = 0 To 3 $aMatch = StringRegExp($aStr[$i], $sRegEx, 3) If IsArray($aMatch) Then _ArrayDisplay($aMatch) Next Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now