Jump to content
Sign in to follow this  
gcue

stringregexp matches

Recommended Posts

gcue

i have an array which is a software list

i would like the user to be able to enter a keyword to search. so if the user enters "acrobat", "adobe acrobat professional" and "acrobat reader" would be a match. what does the stringregexp look like for this?

For $x = 1 To $softwarelist[0]
    $progy = StringRegExp(GUICtrlRead($program)... ;program entered by user
    If $proggy = $softwarelist[$x] Then
        FileWrite($file, $proggy)
    EndIf
Next

thank you for your help =)

Share this post


Link to post
Share on other sites
GEOSoft

Do you mean something like this?

#include<array.au3>
$Ctrl = GUICtrlCreateInput(""........)
For $i = 1 To Ubound($aArray) -1
    If StringRegExp($aArray[$i], "(?i)" & GUICtrlRead($Ctrl)) Then
         $aRtn = StringRegExp($aArray[$i], "(?i).*" & GUICtrlRead($Ctrl) & ".*"), 3)
         If NOT @Error Then
             _ArrayDisplay($aRtn, GUICtrlRead($Ctrl) & " Results")
         EndIf
    EndIf
Next
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

gonna try now - ill let u know!

thanks!

Share this post


Link to post
Share on other sites
GEOSoft

Actually I thought of something after that reply. Why do you need a RegExp? You should just need StringInStr()


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
WideBoyDixon

Or if it's really an array, perhaps _ArrayFindAll() ?

Share this post


Link to post
Share on other sites
gcue

hmm getting an error...

cant see why that line is erroring..

ERROR: syntax error

$aRtn = StringRegExp($softwarelist[$i], "(?i).*" & GUICtrlRead($software) & ".*"),

$softwarelist = _InstalledSoftware($asset[$i][1])
                For $i = 1 To UBound($softwarelist) - 1
                    If StringRegExp($softwarelist[$i], "(?i)" & GUICtrlRead($software)) Then
                        $aRtn = StringRegExp($softwarelist[$i], "(?i).*" & GUICtrlRead($software) & ".*"), 3)
                        If Not @error Then
                            _ArrayDisplay($aRtn, GUICtrlRead($software) & " Results")
                        EndIf
                        
                    EndIf
                Next

Do you mean something like this?

#include<array.au3>
$Ctrl = GUICtrlCreateInput(""........)
For $i = 1 To Ubound($aArray) -1
    If StringRegExp($aArray[$i], "(?i)" & GUICtrlRead($Ctrl)) Then
         $aRtn = StringRegExp($aArray[$i], "(?i).*" & GUICtrlRead($Ctrl) & ".*"), 3)
         If NOT @Error Then
             _ArrayDisplay($aRtn, GUICtrlRead($Ctrl) & " Results")
         EndIf
    EndIf
Next
Edited by gcue

Share this post


Link to post
Share on other sites
GEOSoft

$aRtn = StringRegExp($aArray[$i], "(?i).*" & GUICtrlRead($Ctrl) & ".*", 3)

Just realized thit it might not do what you want anyway. _ArrayGetAll() is a good method to use for this really or Just StringInStr()


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

i cant find _arraygetall.. in the history of releases nor anywhere else in the forum..

do you have a link? =)

thanks geo

Share this post


Link to post
Share on other sites
GEOSoft

i cant find _arraygetall.. in the history of releases nor anywhere else in the forum..

do you have a link? =)

thanks geo

That was my fault. It's _ArrayFindAll()... HelpFile under User Defined Functions>>Array Management

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

ok so far i have this:

$softwarelist = _InstalledSoftware($asset[$i][1])

$searchresults = _ArrayFindAll($softwarelist, GUICtrlRead($software), 0, 0, 0, 1)

_ArrayDisplay($searchresults)

but i get number values as a return.. when i _arraydisplay $softwarelist i get a list of the apps installed on pc ($asset[$i][1])

any ideas?

Share this post


Link to post
Share on other sites
GEOSoft

$softwarelist = _InstalledSoftware($asset[$i][1])
$searchresults = _ArrayFindAll($softwarelist, GUICtrlRead($software), 0, 0, 0, 1)
For $i = 1 To Ubound($SearchResults) -1
   MsgBox(0, "Result " & $i, $SoftwareList[$SearchResults[$i]])
Next

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

Also as I've previously pointed out (twice) this can be done simply with StringInStr($softwarelist[$i][1], $input).


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

cool we're getting somewhere!

but it just reports only one search result.

$softwarelist = _InstalledSoftware($asset[$i][1])oÝ÷ Ú[HÔLND³

Share this post


Link to post
Share on other sites
SmOke_N

If you read the help file, it would show you that it returns the "indexes" of the found values, not the actual string value itself.

This means you have to go outside the box and do a little manipulation yourself on retrieving the index values found out of the array you actually sent.

Edit:

You can even create your own type (I did this one a long time ago before _ArrayFindAll() existed. It works only on 1 dimensional arrays, it returns a 2 dimensional array, [n][0] (2nd dimension, 0 index) returns the index it was found in the original array, [n][1] (2nd dimension, index 1) returns the string value found for that index.

#include <array.au3>

Global $a_tmp[3] = ["apple", "orange", "strange"]

Global $a_ret = _array_find_matches($a_tmp, "ran")
_ArrayDisplay($a_ret)

; Return a 2D array [n][0] = index number in original array: [n][1] = match string value
; $f_exact_match is not case sensitive, unless $f_case_sensitive is set to true
Func _array_find_matches($a_array, $s_match, $i_base = 0, $f_exact_match = False, $f_case_sensitive = False)
    Local $i_case = 0
    If $f_case_sensitive Then $i_case = 1
    
    Local $i_ub = UBound($a_array)
    If $i_ub - 1 < $i_base Then Return SetError(1, 0, 0)
    
    Local $a_ret_array[$i_ub][2], $i_add = 0
    
    For $i = $i_base To $i_ub - 1
        If $f_exact_match Then
            If $f_case_sensitive Then
                If ($a_array[$i] == $s_match) Then
                    $a_ret_array[$i_add][0] = $i
                    $a_ret_array[$i_add][1] = $a_array[$i]
                    $i_add += 1
                EndIf
            Else
                If $a_array[$i] = $s_match Then
                    $a_ret_array[$i_add][0] = $i
                    $a_ret_array[$i_add][1] = $a_array[$i]
                    $i_add += 1
                EndIf
            EndIf
        ElseIf StringInStr($a_array[$i], $s_match, $i_case) Then
            $a_ret_array[$i_add][0] = $i
            $a_ret_array[$i_add][1] = $a_array[$i]
            $i_add += 1
        EndIf
    Next
    
    If Not $i_add Then Return SetError(2, 0, 0)
    
    ReDim $a_ret_array[$i_add][2]
    Return $a_ret_array
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
gcue

this was getting overtly complicated..

so i followed ur advice geo..

$softwarelist = _InstalledSoftware($asset[$i][1])               
                For $z = 1 To $softwarelist[0]
                    $searchresults = StringInStr($softwarelist[$z], GUICtrlRead($software))
                    If $searchresults <> 0 Then
                        FileWrite($file, '' & @CRLF & _
                                $asset[$i][0] & "," & $asset[$i][1] & "," & $sections[$x] & "," & $softwarelist[$z])
                    EndIf
                Next

thanks for your help everyone!

Share this post


Link to post
Share on other sites
gcue

if GUICtrlRead($software) is more than two words..

how can i account for the spaces as a wildcard?

for instance:

if someone searches for Sametime 7.5 - Sametime Connect 7.5 would come back as a match

$softwarelist = _InstalledSoftware($asset[$i][1])            
                For $z = 1 To $softwarelist[0]
                    $searchresults = StringInStr($softwarelist[$z], GUICtrlRead($software))
                    If $searchresults <> 0 Then
                        FileWrite($file, '' & @CRLF & _
                                $asset[$i][0] & "," & $softwarelist[$z])
                    EndIf
                Next
Edited by gcue

Share this post


Link to post
Share on other sites
Xenobiologist

I would be much easier, if you just use the software list as a normal string an then search the string with StringInStr or RegExp


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
gcue

hmmm not sure what you mean.. "normal string?"

Edited by gcue

Share this post


Link to post
Share on other sites
Xenobiologist

hmmm not sure what you mean.. "normal string?"

Just like _ArrayToString. So at the end you have a string to search on like:

$installedSoftware = 'Autoit 3|Lotus Notes|Irfan View|...'

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
gcue

how would that help with the wildcard thing?

thanks for your help xeno

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  

×