0
votes

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 \

1
I'm not familiar with AuthoHotKey. What is the result for 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 try FoundPos := RegExMatch("G:\\htdocs\\projects\\webdevapp\\app\\folder\\file.php", "G:\\htdocs\\projects\\(.*)\\app\\folder\\file.php", DomainNameVar) - Attilio
@Attilio I will update the question as this part \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 it G:\\htdocs\\projects\\[^\\]* matches G:\htdocs\projects\webdevapp on this string G:\htdocs\projects\webdevapp\app\folder\file.php demo - regex101.com/r/rFQRbT/1 - JasonDavis

1 Answers

1
votes

I got it!

FoundPos := RegExMatch("G:\htdocs\projects\webdevapp\app\folder\file.php", "G:\\htdocs\\projects\\([^\\]+)*", DomainNameVar) 

G:\\htdocs\\projects\\([^\\]+)*

Demo https://regex101.com/r/rFQRbT/1