I am trying to check if a string is in a string using RegEx in a AutoHotKey script.
If my string is a file path like this:
G:\htdocs\projects\webdevapp\app\folder\file.php
Then I need to extract the webdevapp
part.
From the AutoHotKey docs it gives this example for a RegEx command that will store the found value to a variable:
; Returns 1 and stores "XYZ" in SubPat1.
FoundPos := RegExMatch("abcXYZ123", "abc(.*)123", SubPat)
So in theory something similar to this below except the regex part would need to be changed...
FoundPos := RegExMatch("G:\htdocs\projects\webdevapp\app\folder\file.php", "G:\htdocs\projects\(.*)\app\folder\file.php", DomainNameVar)
Any help in extracting that domain name from the file path into a variable in AutoHotKey?
It basically need to check if the string starts with G:\htdocs\projects\
and if it does then grab any character after that point until it comes up to the next \
FoundPos := RegExMatch("G:\htdocs\projects\webdevapp\app\folder\file.php", "G:\htdocs\projects\(.*)\app\folder\file.php", DomainNameVar)
(you might want to include that into the question for reference). In many systems "\" might be a special character, so you might want to tryFoundPos := RegExMatch("G:\\htdocs\\projects\\webdevapp\\app\\folder\\file.php", "G:\\htdocs\\projects\\(.*)\\app\\folder\\file.php", DomainNameVar)
- Attilio\app\folder\file.php
should not be in the regex as it will be different for each string. I gort this regex test to match everything up until the end of the string I need if I can just get the result to remove the first part from itG:\\htdocs\\projects\\[^\\]*
matchesG:\htdocs\projects\webdevapp
on this stringG:\htdocs\projects\webdevapp\app\folder\file.php
demo - regex101.com/r/rFQRbT/1 - JasonDavis