argumentum 567 Posted June 16, 2019 (edited) I know nothing about RegExp. Too complicated for my brain cells All I need is to find, say: C:\Users\Other\AppData\Local\Temp\~TEST~\ ( that I can do with StringInStr ) C:\Users\*\AppData\Local\Temp\* ( that I can NOT do with StringInStr ) I'll use this to skip matching paths ala StringInStr. Thanks Answered at https://www.autoitscript.com/forum/topic/199287-solved-regexp-path/?do=findComment&comment=1429890 Edited June 16, 2019 by argumentum Solved Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
FrancescoDiMuro 424 Posted June 16, 2019 @argumentum What do you need to skip? Not so clear, sorry Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Share this post Link to post Share on other sites
TheXman 405 Posted June 16, 2019 (edited) Something like this maybe? #include <Constants.au3> #include <Array.au3> example() Func example() ; Finds C:\Users\*\AppData\Local\Temp\* Const $kRegex = "(?i)C:\\Users\\[^\\]+\\AppData\\Local\\Temp\\.*" Local $sData $sData &= "C:\Users\Other\AppData\Local\Temp\~TEST~\" & @CRLF ; Match $sData &= "C:\users\Joe\appdata\local\temp\test" & @CRLF ; Match $sData &= "C:\Users\Mary\AppData\Local\Temp2\Test" & @CRLF ; No match because "Temp2" Local $aResult = StringRegExp($sData, $kRegex, $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult) EndFunc Spoiler (?i)C:\\Users\\[^\\]+\\AppData\\Local\\Temp\\.* Use these options for the whole regular expression «(?i)» Case insensitive «i» Match the character string “C:” literally (case insensitive) «C:» Match the backslash character «\\» Match the character string “Users” literally (case insensitive) «Users» Match the backslash character «\\» Match any character that is NOT the backslash character «[^\\]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» Match the backslash character «\\» Match the character string “AppData” literally (case insensitive) «AppData» Match the backslash character «\\» Match the character string “Local” literally (case insensitive) «Local» Match the backslash character «\\» Match the character string “Temp” literally (case insensitive) «Temp» Match the backslash character «\\» Match any single character that is NOT a line break character (line feed) «.*» Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» Edited June 16, 2019 by TheXman Made 2nd example lowercase to emphasize need to make regex case-insensitive About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 (edited) @FrancescoDiMuro, what @TheXman did but as a function returning true/false on the path as a string. _IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\Users\Other\AppData\Local\Temp\~TEST~\") ; that I can do with StringInStr _IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\Users\*\AppData\Local\Temp\*") ; that I can NOT do with StringInStr func _IsThisInThePath($sFullPath, $sMatchThis) if $sFullPath match $sMatchThis via regular expresion then Return True else Return False endIf endFunc or the like. Edited June 16, 2019 by argumentum Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
TheXman 405 Posted June 16, 2019 (edited) So something like this? #include <Constants.au3> #include <Array.au3> Const $kRegex = "(?i)C:\\Users\\[^\\]+\\AppData\\Local\\Temp\\.*" ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", $kRegex) & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp2\~TEST~\", $kRegex) & @CRLF) ConsoleWrite(_IsThisInThePath("c:\users\mary\appdata\local\temp\~test~\", $kRegex) & @CRLF) Func _IsThisInThePath($sPath, $sRegex) Return StringRegExp($sPath, $sRegex) EndFunc Edited June 16, 2019 by TheXman About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 actually, given that regexp do more than 1 comparing at the time, I'd like to match more than one matching, like, find: "C:\Users\Other\AppData\Local\Temp\~TEST~\" in: "C:\Users\*\AppData\Local\Temp\*", "C:\anotherPath\*\subfolder\", etc. if it matches any of the in return true Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 2 minutes ago, TheXman said: So something like this? yes but like ConsoleWrite(_IsThisInThePath("c:\users\mary\appdata\local\temp\~test~\", "C:\Users\*\AppData\Local\Temp\*") & @CRLF) Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 lol, since I'm clueless about StringRegExp, I guess your code is what can be done. I'll take it from there if that is that Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
TheXman 405 Posted June 16, 2019 (edited) So something like this maybe? #include <Constants.au3> #include <Array.au3> ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp2\~TEST~\", "C:\users\*\appdata\local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("c:\users\mary\appdata\local\temp\~test~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) Func _IsThisInThePath($sPath, $sPattern) ; Convert plain text pattern to regular expression $sPattern = "(?i)" & $sPattern $sPattern = StringReplace($sPattern, "\", "\\") $sPattern = StringReplace($sPattern, "*", "[^\\]+") Return StringRegExp($sPath, $sPattern) EndFunc Edited June 16, 2019 by TheXman 1 argumentum reacted to this About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 (edited) Exactly @TheXman. Now, can I do more than 1 RegExp in the matching, or is it one by one only ? ( the question higher up ) Edited June 16, 2019 by argumentum Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
TheXman 405 Posted June 16, 2019 Just now, argumentum said: Now, can I do more than 1 RegExp in the matching, or is it one by one only ? Yes, the possibilities are endless. It just depends on your imagination and ability to implement it. 1 argumentum reacted to this About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 lol, I have ... none at the time. But my OP is answered. Thanks a million Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
TheXman 405 Posted June 16, 2019 (edited) You're welcome! Here's a little quick & dirty implementation of one way to pass multiple patterns. Basically, I created it so that you separate multiple patterns with "|". So you can have as many as you'd like. Also, as you can see, I didn't add any error checking, which it certainly would need. #include <Constants.au3> #include <Array.au3> ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\users\*\appdata\*\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp2\~TEST~\", "C:\users\*\appdata\local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("c:\users\mary\appdata\local\temp\~test~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\abc\def\ghi\Local\Temp\~TEST~\", "C:\users\*\appdata\*\Temp\|C:\abc\*\ghi\") & @CRLF) ;Multiple patterns Func _IsThisInThePath($sPath, $sPattern) Local $bPathFound = False Local $aPatterns Local $sRegex ; Split multiple patterns into an array of patterns and ; spin thru patterns to see if any match. $aPatterns = StringSplit($sPattern, "|") For $i = 1 To $aPatterns[0] $sRegex = $aPatterns[$i] $sRegex = "(?i)" & $sRegex $sRegex = StringReplace($sRegex, "\", "\\") $sRegex = StringReplace($sRegex, "*", "[^\\]+") If StringRegExp($sPath, $sRegex) Then $bPathFound = True Next Return $bPathFound EndFunc Or my previous function would work too since the "|" character is the regex way of having multiple patterns. #include <Constants.au3> #include <Array.au3> ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp\~TEST~\", "C:\users\*\appdata\*\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\Users\Other\AppData\Local\Temp2\~TEST~\", "C:\users\*\appdata\local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("c:\users\mary\appdata\local\temp\~test~\", "C:\Users\*\AppData\Local\Temp\") & @CRLF) ConsoleWrite(_IsThisInThePath("C:\abc\def\ghi\Local\Temp\~TEST~\", "C:\users\*\appdata\*\Temp\|C:\abc\*\ghi\") & @CRLF) ;Multiple patterns Func _IsThisInThePath($sPath, $sPattern) ; Convert plain text pattern to regular expression $sPattern = "(?i)" & $sPattern $sPattern = StringReplace($sPattern, "\", "\\") $sPattern = StringReplace($sPattern, "*", "[^\\]+") Return StringRegExp($sPath, $sPattern) EndFunc Edited June 16, 2019 by TheXman 1 argumentum reacted to this About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
argumentum 567 Posted June 16, 2019 33 minutes ago, TheXman said: y previous function would work too since the "|" character is the regex way of having multiple patterns ..and that answers it all !. ( the Semper volens auxilium is true ) Again, thanks @TheXman 1 TheXman reacted to this Follow the link to see my signature's stuff. Share this post Link to post Share on other sites