Question

I handle many documents on a day to day basis and was using regular expression and Autohotkey to open a particular page of pdf from a given string. For ex, I will copy the below string including the parenthesis and press a hotkey

(16G3537-2011 tax return-page 25)

Any my below Ahk code would open the 25th page in the pdf 16G3537-2011 tax

RegExMatch(clipboard,"i)\((.*)\s*-page\s*(\d+)\)",part)
Run, %Adobelocation% /A page=%part2% %copyz%/%part1%.pdf"

Adobelocation is the location of adobe reader in my computer

copyz is the location of folder where the pdf is located

I know AHK to some extent, but have difficulty with regular exp. Now my query string has been modified to just

16G3537-2011 tax return.pdf_pages 25

I am really at a loss to make my code open the 25th page using the modified string. Kindly help me.

Edit:

The command line for this code is

Run, pathto\Acrobat.exe /A "page=" part2 " C:\folder\" part1 ".pdf"

Was it helpful?

Solution

Try

RegExMatch(clipboard,"i)(.*)\s*\.pdf_pages\s*(\d+)",part)
Run, %Adobelocation% /A page=%part2% %copyz%/%part1%.pdf"

The difference to the original regex is the Elimination of the parenthesis matching (\(, \)) and the Substitution of the separator Char in Front of the page specific (\. instead of -).

Note That since the parentheses around the file name have been dropped, you'd need some other Marker to indicate the Start of the relevant expression if you'd Extract from embedding Text. The context you give suggests that this is not necessary in your Case ( the clipboard containing only the relevant data), but keep it in mind when reusing the regex.

Still wondering why return would not be Part of the extracted file name, but you Write that the original Works so i let this Aspect Rest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top