NMS Posted February 7, 2023 Share Posted February 7, 2023 Hello. I've browsed the forums for a while however wasn't able to find exactly what I'm looking for. I have the following string as example with characters marked in bold as my desired match (full file path): test text "" HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png This string has 2 hyperlinks with only one reffering to the actual file, while the other one points to the folder. The string can have only 1 full file path, however its placement can vary. This function is running inside the WM_NOTIFY message as I am getting the text that is currently under the mouse position so the less steps it takes to get the final link the better. Basically what I need is always in between HYPERLINK " and .png" $sLink = StringRegExpReplace($sText, '(HYPERLINK ")[\s\S]*?(?=png")', '$1') The above is best what I got and even that is far from the desired result. Link to comment Share on other sites More sharing options...
Danp2 Posted February 7, 2023 Share Posted February 7, 2023 (edited) Here's a simple example using StringRegExp instead of StringRegExpReplace -- #include <Array.au3> $sText = ' test text "" HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png ' $sRegExp = 'HYPERLINK "(.*?)"' $aResults = StringRegExp($sText, $sRegExp, $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResults) Edit: OIC that I missed the requirement to ignore the "folder" link. 🙁 Edited February 7, 2023 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Solution pixelsearch Posted February 7, 2023 Solution Share Posted February 7, 2023 Here is what I use for this kind of things, hope it will help in a way or another : (?is)"([^"]*?\.(?:jpg|png))" Zedna 1 Link to comment Share on other sites More sharing options...
AutoBert Posted February 7, 2023 Share Posted February 7, 2023 RegEx is not realy needed: $sText = ' HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png ' $sbefore = '- HYPERLINK "' $sAfter ='"6' $iStart = StringInStr($sText, $sbefore) $iEnd = StringInStr($sText, $sAfter) $iCount = $iEnd - $iStart - StringLen($sbefore) ConsoleWrite ($iStart & '|' & $iEnd & '|' & $iCount & @CRLF) $sResult = StringMid($sText, $iStart + StringLen($sbefore), $iCount) MsgBox(64, 'Result: ', $sResult, 15) Link to comment Share on other sites More sharing options...
bdr529 Posted February 7, 2023 Share Posted February 7, 2023 #include <string.au3> $sText = ' HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png ' local $ext='.png' local $_StringBetween=_StringBetween($sText,'- HYPERLINK "',$ext) if not @error then MsgBox(64,'Result: ',$_StringBetween[0]&$ext) To community goes all my regards and thanks Link to comment Share on other sites More sharing options...
NMS Posted February 8, 2023 Author Share Posted February 8, 2023 While I appreciate the other responses they wouldn't work since: $sText = ' HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png ' $sbefore = '- HYPERLINK "' $sAfter ='"6' ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This assumes it always ends at 6 $iStart = StringInStr($sText, $sbefore) $iEnd = StringInStr($sText, $sAfter) $iCount = $iEnd - $iStart - StringLen($sbefore) ConsoleWrite ($iStart & '|' & $iEnd & '|' & $iCount & @CRLF) $sResult = StringMid($sText, $iStart + StringLen($sbefore), $iCount) MsgBox(64, 'Result: ', $sResult, 15) #include <string.au3> $sText = ' HYPERLINK "A:\test\folder\1"[Folder] more test text - HYPERLINK "A:\test\folder\1\6-07-02-2023-13-52-46-1.png"6-07-02-2023-13-52-46-1.png ' local $ext='.png' local $_StringBetween=_StringBetween($sText,'- HYPERLINK "',$ext) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While this, starts with - HYPERLINK " if not @error then MsgBox(64,'Result: ',$_StringBetween[0]&$ext) 18 hours ago, NMS said: Basically what I need is always in between HYPERLINK " and .png" ...everything else is variable. I did change a little pixelsearch's answer to suit my case better and with less steps in the end: (?is)HYPERLINK "([^"]*?\.(?:png")) Link to comment Share on other sites More sharing options...
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