Jump to content

Does AutoIt Support Wildcards?


 Share

Go to solution Solved by czardas,

Recommended Posts

$oIE = _IECreate("http://google.com")
Local $pTitle = WinGetTitle("[ACTIVE]")

If $pTitle = ("* - Internet Explorer") Then
 Sleep(3000)
EndIf

Basically I need to know how to get the asterisk to function as a wildcard; is this possible?

Link to comment
Share on other sites

That's not what I'm looking for. I need to know if it's possible to use a character as a wildcard for substituting information.

I need to be able to do this (just an example):

"This is a sentence about a fish toy."

"This is a sentence about a dog toy."

"This is a sentence about a cat toy."

Find: "This is a sentence about a * toy."

 

Link to comment
Share on other sites

That link is exactly what you're looking for, unless you want someone to tell you how to do it rather than reading that page and learning from it.

Use a REGEXPTITLE for the title, or CLASS or a partial title match using the WinTitleMatchMode option.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

In some AutoIt functions, asterisk represents any acceptable sequence of characters, but this is certainly not universal. If you want to use asterisk in other circumstances, then you have to create the code to interpret the characters as you prefer. Here's an example, but it's slightly complicated because of the regular expressions:

;

Local $sString = "whatever - Internet Explorer"
Local $sQuery = "* - Internet Explorer"

Local $sPattern = StringRegExpReplace($sQuery,  "[\W]", "\\$0") ; Ignore special character meanings
$sPattern = "(" & StringReplace($sPattern, "\*", ".*") & ")" ; Dot in the pattern signifies any characters may appear.

If StringRegExp($sString, $sPattern) Then
    MsgBox(0, "", "Match Found")
EndIf
Edited by czardas
Link to comment
Share on other sites

That link is exactly what you're looking for, unless you want someone to tell you how to do it rather than reading that page and learning from it.

 

Actually that link is exactly not what I'm looking for, and I don't appreciate you passive-aggressively implying I'm too lazy to read the page. What I'm looking for isn't exclusive to window titles. In fact, in the case I'm looking for it's not even related to titles at all - I just used that snippet of script as an example for what I meant by a wildcard character.

Here's some situations where I'd like to be able to use the wildcard:

https://www.google.com/search?q=boston+art+museums
https://www.google.com/search?q=broadway+musicals
https://www.google.com/search?q=new+cinematography
https://www.google.com/search?q=ice+hockey+canada

I need to use a wildcard so I can execute something like finding "https://www.google.com/search?q=b*" and outputting it into a .txt file.
Text file 1 says "Hello, my name is John and this is my thesis paper. I once . . ."
Text file 2 says "Hello, my name is Mark and this isn't my thesis paper. I once . . ."

I need to use a wildcard so I can execute something like finding "* this is my thesis paper *" to find only files that include those words.

I know there are alternative methods to doing this, but that's not what I want. I want to know if using a wildcard is possible, and how to do it.

Link to comment
Share on other sites

Regular expressions:

$string = "blahblahhttps://www.google.com/search?q=boston+art+museums more stuff"
$a = StringRegExp($string,"(https[^\s]+)",3)
ConsoleWrite($a[0] & @CRLF)
$a = StringRegExp($string,"(?U)(https.*)\s",3)
ConsoleWrite($a[0] & @CRLF)

Your second example needs no wild card...use:

StringInStr
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Incredible you attitute. The link is correct...for title is REGEXP, for "string" is StringRegExp, for search file with wildcard use_RecFileListToArray / _FileListToArray

Don't change the OP during the thread:

"In fact, in the case I'm looking for it's not even related to titles at all"

So why do you post THAT example...? And don't post directly what you want to do? Many, many way to skin a cat.

Link to comment
Share on other sites

 

In some AutoIt functions, asterix represents any acceptable sequence of characters, but this is certainly not universal. If you want to use asterix in other circumstances, then you have to create the code to interpret the characters as you prefer. Here's an example, but it's slightly complicated because of the regular expressions:

;

Local $sString = "whatever - Internet Explorer"
Local $sQuery = "* - Internet Explorer"

Local $sPattern = StringRegExpReplace($sQuery,  "[\W]", "\\$0") ; Ignore special character meanings
$sPattern = "(" & StringReplace($sPattern, "\*", ".*") & ")" ; Dot in the pattern signifies any characters may appear.

If StringRegExp($sString, $sPattern) Then
    MsgBox(0, "", "Match Found")
EndIf

 

 

Regular expressions:

$string = "blahblahhttps://www.google.com/search?q=boston+art+museums more stuff"
$a = StringRegExp($string,"(https[^\s]+)",3)
ConsoleWrite($a[0] & @CRLF)
$a = StringRegExp($string,"(?U)(https.*)\s",3)
ConsoleWrite($a[0] & @CRLF)

Your second example needs no wild card...use:

StringInStr

Thanks guys, I'll give these a try!

 

Incredible you attitute. The link is correct...for title is REGEXP, for "string" is StringRegExp, for search file with wildcard use_RecFileListToArray / _FileListToArray
Don't change the OP during the thread:
"In fact, in the case I'm looking for it's not even related to titles at all"

So why do you post THAT example...? And don't post directly what you want to do? Many, many way to skin a cat.

 

I appreciate you linking to a page that you thought would help, but it wasn't the thing I was looking for, which is why I stated it wasn't what I was looking for and gave another example.
I posted that example because any example is just as good, I wasn't asking how to find the title another way, I was asking specifically how to use an asterisk as a wildcard.

I'm sorry if you feel like I had an attitude with you; I don't.

Edited by 4b0082
Link to comment
Share on other sites

  • Solution

In SRE, asterisk has a different meaning, so you can see there are various interpretations - not only used for wildcards. I often forget someone might want case insensitive matches, so here's another version.

;

Local $sString = "tHIs IS A senTEnce aBOut A CAt TOy."
Local $sQuery = "This is a sentence about a * toy."

Local $sPattern = StringRegExpReplace($sQuery,  "[\W]", "\\$0") ; Ignore special character meanings
$sPattern = "(?i)(" & StringReplace($sPattern, "\*", ".*") & ")" ; Dot in the pattern signifies any characters may appear.

If StringRegExp($sString, $sPattern) Then
    MsgBox(0, "", "Match Found")
EndIf

;

It's not much different from my previous example.

Edited by czardas
Link to comment
Share on other sites

In SRE, asterisk has a different meaning, so you can see there are various interpretations - not only used for wildcards. I often forget someone might want case insensitive matches, so here's another version.

;

Local $sString = "tHIs IS A senTEnce aBOut A CAt TOy."
Local $sQuery = "This is a sentence about a * toy."

Local $sPattern = StringRegExpReplace($sQuery,  "[\W]", "\\$0") ; Ignore special character meanings
$sPattern = "(?i)(" & StringReplace($sPattern, "\*", ".*") & ")" ; Dot in the pattern signifies any characters may appear.

If StringRegExp($sString, $sPattern) Then
    MsgBox(0, "", "Match Found")
EndIf

;

It's not much different from my previous example.

Awesome, I was able to use this for exactly what I needed. Thanks a million, czardas!

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...