Jump to content

Find string in regread


Recommended Posts

I search how to find a string in a regread function.

Do you have some example?. Anyway, maybe this example could help to you:

$var = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "Version") ;First read the content of the value name
$stringToSearch = "3.3" ;Search what you need
$result = StringRegExp($var,$stringToSearch) ;Here we check if our pattern ($stringToSearch) exists

If $result = 1 Then
    MsgBox(0,"","I've found the string " & $stringToSearch & " on the following text: " & $var)
Else
    MsgBox(0,"","Sorry but I didn't find the string " & $stringToSearch & " on the following text: " & $var)
EndIf
Link to comment
Share on other sites

Do you have some example?. Anyway, maybe this example could help to you:

$var = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "Version") ;First read the content of the value name
$stringToSearch = "3.3" ;Search what you need
$result = StringRegExp($var,$stringToSearch) ;Here we check if our pattern ($stringToSearch) exists

If $result = 1 Then
    MsgBox(0,"","I've found the string " & $stringToSearch & " on the following text: " & $var)
Else
    MsgBox(0,"","Sorry but I didn't find the string " & $stringToSearch & " on the following text: " & $var)
EndIf

You got lucky on that RegExp. Technically it's incorrect although when searching that particular key it will work.

EDIT: You can easily fix the problem with this added line

$stringToSearch = "3.3" ;Search what you need
$stringToSearch = StringRegExpReplace($stringToSearch, "([.?\\\[\]\(\)\{\}^])", "\\$1");; Escape special characters, I may have missed some though
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!"

Link to comment
Share on other sites

You got lucky on that RegExp. Technically it's incorrect although when searching that particular key it will work.

You are right, it was just a quick example but thanks for show us the right way. Anyway, I'm going to start learning PCRE (I've already downloaded your PCRE Toolkit to practice hehe) because I always get stuck trying to figure out what's the best RegEx to accomplish the goal ;-).

Thank you again (for the answer and for your toolkit).

sahsanu

Link to comment
Share on other sites

You are right, it was just a quick example but thanks for show us the right way. Anyway, I'm going to start learning PCRE (I've already downloaded your PCRE Toolkit to practice hehe) because I always get stuck trying to figure out what's the best RegEx to accomplish the goal ;-).

Thank you again (for the answer and for your toolkit).

sahsanu

Glad to hear you are trying the toolkit, although you should remember it still beta. I have another update ready now but it won't be uploaded until tomorrow.

Edit. It also could be done quite simple by using

$result = StringRegExp($var,"\Q" & $stringToSearch & "\E")
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!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...