brycetech Posted May 7, 2012 Share Posted May 7, 2012 Hi lets assume you have ran a regex and have obtained three strings from the search. assume these matches are: test.missing test1.missing test.missing 1 and 3 are the same... what means would you suggest to return the position in the search text of those strings? What I am doing is performing a regex search on multiple files..the search returns a listview which contains the file name that matches the search in column 1 and the matched text in column 2. When I double click on the row/column, the file opens..my next task is to make it highlight the current match I have doubleclicked. If I double click #3 above, I need to know the position in the text. I am not aware of any flag that returns this position. Have I missed this? or perhaps some suggestions on how to approach this tia BT Link to comment Share on other sites More sharing options...
czardas Posted May 7, 2012 Share Posted May 7, 2012 This is what I would do - after the regexp, loop through the array and use StringInStr to get the positions. Count the number of times you encounter a particular match in order to increment the occurence. You may wish to use _ArrayUnique before searching for the positions because duplicates may exist such as in your example. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2012 Moderators Share Posted May 7, 2012 (edited) brycetech,You could use the Offset parameter in StringRegExp like this to find the positions of all instances of the search string:#include <array.au3> Global $aArray[3] $sString = "test.missing test1.missing test.missing" ; | | | | ; 1 6 21 36 $sFind = "missing" $iAdjust = StringLen($sFind) $iOffset = 1 For $i = 0 To 2 $aTemp = StringRegExp($sString, $sFind, 1, $iOffset) $iOffset = @extended ; Offset is the end of the searchstring so we need to reset to the start $aArray[$i] = $iOffset - $iAdjust Next _ArrayDisplay($aArray)Any use? M23 Edited May 7, 2012 by Melba23 Cannot count - see below 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...
czardas Posted May 7, 2012 Share Posted May 7, 2012 That's interesting Melba. I wonder if there is any advantage to doing it that way. I'll have to figure that out later. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Malkey Posted May 7, 2012 Share Posted May 7, 2012 @M23 Close, but not quite right. $sString = "test.missing test1.missing test.missing" ;...........|....|..............|..............| ;...........1....5..............20.............35 <- Script results ;...........1....6..............21.............36 <- counting the characters Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2012 Moderators Share Posted May 7, 2012 Malkey, Never could count! Previous post amended, thanks. M23 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...
czardas Posted May 7, 2012 Share Posted May 7, 2012 (edited) I just ran a quick test and it appears that StringInStr is more than twice as fast with this particular example. However it is difficult to decide what is a fair test. With a more complicated regexp pattern using StringInStr could be annoying and the speed difference will vary. Also with this example, the regexp version requires more lines of code: so it's not entirely clear (but still very interesting nonetheless). #include <Array.au3> Global $aArray[3] $sString = "test.missing test1.missing test.missing" $sFind = "missing" $iAdjust = StringLen($sFind) $iTimer = TimerInit() For $j = 1 To 100 _REVersion() Next ConsoleWrite(">>> " & TimerDiff($iTimer) & " <<<" &@CRLF) $iTimer = TimerInit() For $j = 1 To 100 _SISversion() Next ConsoleWrite(">>> " & TimerDiff($iTimer) & " <<<" &@CRLF) Func _REVersion() $iOffset = 1 For $i = 0 To 2 $aTemp = StringRegExp($sString, $sFind, 1, $iOffset) $iOffset = @extended $aArray[$i] = $iOffset - $iAdjust Next EndFunc Func _SISversion() For $i = 0 To 2 $aTemp = StringInStr($sString, $sFind, 1, $i +1) $aArray[$i] = $aTemp Next EndFunc Perhaps this is a fairer test. #include <Array.au3> Global $aArray[3] $sString = "test.missing test1.missing test.missing" $sFind = "missing" $iAdjust = StringLen($sFind) $iOffset = 1 $iTimer = TimerInit() For $j = 1 To 1000 _REVersion() Next ConsoleWrite(">>> " & TimerDiff($iTimer) & " <<<" &@CRLF) $iTimer = TimerInit() For $j = 1 To 1000 _SISversion() Next ConsoleWrite(">>> " & TimerDiff($iTimer) & " <<<" &@CRLF) Func _REVersion() For $i = 0 To 2 StringRegExp($sString, $sFind, 1, $iOffset) Next EndFunc Func _SISversion() For $i = 0 To 2 StringInStr($sString, $sFind, 1, $i +1) Next EndFunc Edited May 7, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
zpanderson Posted August 13, 2012 Share Posted August 13, 2012 Is there a way for the StringRegExp function to just return a 2D array when asking for an array return with the 2nd dimension being the offset of each result? 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