TimRude Posted yesterday at 04:40 AM Posted yesterday at 04:40 AM (edited) I'm trying to find a Window using WinGetHwnd("[REGEXPTITLE: ...]") but I can't figure out how to get it to work with some wildcards. The window title I'm trying to match will look like this: SampleApp 1234 - some text here (12345678 - some more miscellaneous text) I want to match only windows that start with 'SampleApp #### - ', and then can have any text, and then have ' (########' followed by any other text. The 4-digit grouping and the the 8-digit grouping can be made up of any digits, and the the length of 'some text here' and 'some more miscellaneous text' may vary. [REGEXPTITLE:(?i)SampleApp \d\d\d\d - *] matches my sample title but it only checks the beginning of the title, which isn't enough. How can I get it to also check that there's a ' (########' string later on in the title? [REGEXPTITLE:(?i)SampleApp \d\d\d\d - * \(\d\d\d\d\d\d\d\d*] does not work and my test title isn't matched at all. In fact, if I use the * character in the pattern followed by anything after it, I get no matches. What basic bit of RegExp magic am I missing? Edited 23 hours ago by TimRude
TimRude Posted yesterday at 04:46 AM Author Posted yesterday at 04:46 AM (edited) Nevermind, I just figured it out. I had to add a . before the first * This works: [REGEXPTITLE:(?i)SampleApp \d\d\d\d - .* \(\d\d\d\d\d\d\d\d*] Not sure exactly why the . is needed before the * but it works. If anyone cares to explain why .* works when * doesn't, I'm all ears. Edited 23 hours ago by TimRude
Solution Musashi Posted 22 hours ago Solution Posted 22 hours ago (edited) 1 hour ago, TimRude said: Not sure exactly why the . is needed before the * but it works. If anyone cares to explain why .* works when * doesn't, I'm all ears. .* is required because : . -> matches any single character except, by default, a newline sequence. * -> 0 or more, greedy * alone is a Quantifier (or repetition specifier) which specifies how many of the preceding characters are expected to match. Info : \d\d\d\d can be written as \d{4} Global $sStr = "SampleApp 1234 - some text here 12345678 - some more miscellaneous text" Global $sPattern = "(?i)SampleApp \d{4} -.*\d{8} -.*" ConsoleWrite(StringRegExp($sStr, $sPattern) & @LF) ; Returns 1 (match) or 0 (no match) Edited 22 hours ago by Musashi typo TimRude and pixelsearch 1 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
pixelsearch Posted 22 hours ago Posted 22 hours ago (edited) It's because the quantifiers (* + ? { }) "specify how many of the preceding character, class, reference or group are expected to match." ( @jchd in help file, topic StringRegExp) So space* will check for 0 or more repeated spaces, while .* will check for 0 or more any character (except newline characters when the option (?s) is not indicated) Edit : @Musashi was fast Edited 22 hours ago by pixelsearch Musashi and TimRude 1 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
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