Deye Posted July 3, 2016 Share Posted July 3, 2016 (edited) Hi, I'm trying to make a function that will catch all these phrases (in the array) that are case sensitive to wording that may contain other characters too the combination placements of (*) and (.) in the array are to be treated as patterns, so if the array should grow it will have the same patterns, only with different phrases Starting out with this very raw example .. Main help is needed for the "StringRegExp" search patterns (broken in this example) Of course ,Comments and suggestion on how this function may be improved are Welcome expandcollapse popupDim $wxpr[12] $wxpr[1] = "word" $wxpr[2] = "word.ext" $wxpr[3] = "word.*" $wxpr[4] = "*.ext" $wxpr[5] = "*.word*" $wxpr[6] = "*word*.*" $wxpr[7] = "*.*word" $wxpr[8] = "*word*.ext" $wxpr[9] = "word*.*" $wxpr[10] = "*word%word%word%word.*" $wxpr[11] = "word%word%word*.*" MsgBox(0, "_match", _match("this word and.ext")) Func _match($aVal) For $i = 1 To UBound($wxpr) - 1 If Not StringInStr($wxpr[$i], "*") Then ;should match to $wxpr[1] ,$wxpr[2] If $wxpr[$i] = $aVal Then Return 1 EndIf ElseIf StringInStr($wxpr[$i], "*.*") Then Local $iPosition = StringInStr($wxpr[$i], "*.*") If $iPosition <> 1 Then StringReplace($wxpr[$i], "*", "*") If @extended > 2 Then ;should match to $wxpr[6] Local $a = StringReplace($wxpr[$i], "*", "") $a = StringReplace($wxpr[$i], ".", "") StringRegExp($aVal, "." & $a & "*\.*.", 0) MsgBox(0, "StringRegExp", $wxpr[$i] & @CRLF & @error) If @error = 1 Then Return 1 Else ;should match to $wxpr[11] EndIf Else ;should match to $wxpr[7] EndIf ElseIf StringInStr($wxpr[$i], ".*") Then StringReplace($wxpr[$i], "*", "*") If @extended > 1 Then ;should match to $wxpr[10] Else ;should match to $wxpr[3] EndIf ElseIf StringInStr($wxpr[$i], "*.") Then Local $iPosition = StringInStr($wxpr[$i], "*.") If $iPosition <> 1 Then ;should match to $wxpr[8] Else StringReplace($wxpr[$i], "*", "*") If @extended > 1 Then ;should match to $wxpr[5] Else ;should match to $wxpr[4] EndIf EndIf EndIf Next Return 0 EndFunc Edited July 3, 2016 by Deye Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 3, 2016 Moderators Share Posted July 3, 2016 Deye, How about this: #include <MsgBoxConstants.au3> Global $wxpr[12] = [11, _ "word", _ "word.ext", _ "word.*", _ "*.ext", _ "*.word*", _ "*word*.*", _ "*.*word", _ "*word*.ext", _ "word*.*", _ "*word%word%word%word.*", _ "word%word%word*.*"] _Match("this word and.ext") Func _Match($sString) For $i = 1 To UBound($wxpr) - 1 ; Convert to SRE pattern (escape PCRE chars and replace "*") $sPattern = StringReplace(StringRegExpReplace($wxpr[$i], "[][$^.{}()+\-]", "\\$0"), "*", ".*?") ; Check translation ConsoleWrite($wxpr[$i] & " - " & $sPattern & @CRLF) ; Try to match If StringRegExp($sString, $sPattern) Then MsgBox($MB_SYSTEMMODAL, "Match", $i & @CRLF & @CRLF & $wxpr[$i]) EndIf Next EndFunc That seems to work for your test string. M23 Deye 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Deye Posted July 3, 2016 Author Share Posted July 3, 2016 (edited) yes, thanks!, very cool Edited July 3, 2016 by Deye 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