Get text between 2 words multiple times

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cdull
Posts: 38
Joined: 11 Jan 2020, 07:34

Get text between 2 words multiple times

19 Apr 2021, 03:18

Hello,

i try to get the text between 2 words multiple times.

I need the text between "/ebooks/pdf/" and ".pdf" from my clipboard.

My code is this at the moment, but it always write the first found and doesn't contine and stop when all found.

Maybe someone know what is missing in my code.

Code: Select all

Clipboard := "<ul class= metis toc-tree manual-toggle ><li><a data-pdf-link= /ebooks/pdf/cs_8456412/263460101_001.pdf  class= tocPdfContainer  href= # >Titelei (PDF)&nbsp;<i class= fa fa-download ></i></a></li><li><a href= #  class= toggler ><span class= fa plus-minus ></span></a><a onclick= toggleNode(this, event)  href= # >Grundlagen</a><ul class= collapse ><li><a data-pdf-link= /ebooks/pdf/cs_8456412/263460101_002_001.pdf  class= tocPdfContainer  href= # >Das Checklistenkonzept" ; later get this from clipboard

testString := Clipboard

loop
{
RegExMatch(testString, "/ebooks/pdf/*\K.*?(?= *.pdf)", results)
FileAppend, %results%`n, %A_Desktop%\result.txt
}
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Get text between 2 words multiple times

19 Apr 2021, 05:11

Code: Select all

file = %A_Desktop%\result.txt
While pos := RegExMatch(testString, "/ebooks/pdf/\K.*?(?=\.pdf)", results, pos ? pos + 1 : 1)
 FileAppend, %results%`n, %file%
Run, %file%
cdull
Posts: 38
Joined: 11 Jan 2020, 07:34

Re: Get text between 2 words multiple times

19 Apr 2021, 09:58

Hey, that works great. Thanks for help.

This is now my code:

Code: Select all

Clipboard := "<ul class= metis toc-tree manual-toggle ><li><a data-pdf-link= /ebooks/pdf/cs_8456412/263460101_001.pdf  class= tocPdfContainer  href= # >Titelei (PDF)&nbsp;<i class= fa fa-download ></i></a></li><li><a href= #  class= toggler ><span class= fa plus-minus ></span></a><a onclick= toggleNode(this, event)  href= # >Grundlagen</a><ul class= collapse ><li><a data-pdf-link= /ebooks/pdf/cs_8456412/263460101_002_001.pdf  class= tocPdfContainer  href= # >Das Checklistenkonzept" ; later get this from clipboard

testString := Clipboard

file = %A_Desktop%\result.txt
While pos := RegExMatch(testString, "/ebooks/pdf/\K.*?(?=\.pdf)", results, pos ? pos + 1 : 1)
FileAppend, %results%`n, %file%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, septrinus and 219 guests