Can't get the correct regex output in Evernote Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Can't get the correct regex output in Evernote

Post by milkygirl90 » 25 Jul 2021, 17:08

Tried the different variations but it didn't work.

Correct output should be: all lines in 1 is collapsed to one line, all lines in 1A is collapsed to one line etc.

Separately, Is there supposed to be some difference between f11 vs ^f11 vs +f11 code?

Code: Select all

!f11:: 
!#v:: 
r := strReplace(clipboard,". `r`n",". ") ;pull text to same row
r := strReplace(r,"`r`n`r`n","`r`n") ;remove blank lines
r := strReplace(r,"`r`n`t","`r`n") ;remove leading tabs
r := strReplace(r,"`t","       ") ;replace tab with spaces
clipboard := r
	SendInput ^v
return

f11:: 
Needle = (?<!\v)\R(?!\R)
clipboard := RegExReplace(RegExReplace(clipboard, Needle, " "), " +", " ")
SendInput, ^v
return

^f11:: ; 1 paragraph 
StringReplace, clipboard, clipboard, `r, , all
   StringReplace, clipboard, clipboard, `n `n, |, all
   StringReplace, clipboard, clipboard, `n`n, |, all
   StringReplace, clipboard, clipboard, `n, %A_Space%, all
   StringReplace, clipboard, clipboard,  |,`r`n`r`n, all
	SendInput ^v
return

+f11:: 
Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*$","`r`n")
; copied from http://ahkscript.org/docs/commands/StringReplace.htm
; Remove all blank lines from the text in a variable:
Loop
 {
   StringReplace, ClipBoard, ClipBoard, `r`n`r`n, --[ahkparagraphmarker]--, UseErrorLevel
   if ErrorLevel = 0  ; No more replacements needed.
     break
 }

;Replace all new lines with a space topreventjoinedwords 
StringReplace, ClipBoard, ClipBoard, `r`n, %A_Space%, All

; Remove all double spaces (useful for justified text)
Loop
 {
    StringReplace, ClipBoard, ClipBoard, %A_Space%%A_Space%, %A_Space%, UseErrorLevel
    if ErrorLevel = 0  ; No more replacements needed.
        break
 }

; re-create paragraphs again
StringReplace, ClipBoard, ClipBoard,--[ahkparagraphmarker]--,`r`n`r`n, All

; remove any leftover remaining leading spaces
Clipboard:=RegExReplace(Clipboard,"m)^[ \t]*")

Send ^v
Return
Image
sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Can't get the correct regex output in Evernote

Post by sofista » 25 Jul 2021, 19:15

Hi: As you posted an image, but not an editable text, I am not sure to have it right. Just tried to format paragraphs with tabs.

Maybe this is what you want

Code: Select all

SampleText =
(
1.	Cannot find amount of shares that a company repurchased, only have the amount spent.
	Outstanding shares actually increase instead of reducing in the quarter. Why?
	a.	In the 10k report, a company may have suspended their share repurchases for FY2020,
		you can try referring to FY2019 10k reports to get some reference figures
2.	The share repurchase price is incredibly low. Does this mean they only repurchased long time ago
	(yr 2004)? Should I still put a +1 in FRIEDD SNAKE?
	a.	Share repurchase can start/stop anytime at the company discretion, it always advisable
		to find the most recent annual/quaterly to get the updated figures, if the last
		repurchase was many years ago, you may want to put a "O" in friedd snake to be
		conservative
)

SampleText := RegExReplace(RegExReplace(SampleText, "\t?(\w\.)\t", "$1 "), "\R\t+", " ")

MsgBox, % SampleText

/* Output:

1. Cannot find amount of shares that a company repurchased, only have the amount spent. Outstanding shares actually increase instead of reducing in the quarter. Why?
a. In the 10k report, a company may have suspended their share repurchases for FY2020, you can try referring to FY2019 10k reports to get some reference figures
2. The share repurchase price is incredibly low. Does this mean they only repurchased long time ago (yr 2004)? Should I still put a +1 in FRIEDD SNAKE?
a. Share repurchase can start/stop anytime at the company discretion, it always advisable to find the most recent annual/quaterly to get the updated figures, if the last repurchase was many years ago, you may want to put a "O" in friedd snake to be conservative
 */
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Can't get the correct regex output in Evernote

Post by milkygirl90 » 25 Jul 2021, 19:28

Hi there,

the output is correct but I can't seem to get mine working:

Code: Select all

f12::Clipboard:=RegExReplace(RegExReplace(Clipboard, "\t?(\w\.)\t", "$1 "), "\R\t+", " ")

Also, will you know the answer to my other question on the different variations of the scripts?
sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Can't get the correct regex output in Evernote

Post by sofista » 25 Jul 2021, 22:45

milkygirl90 wrote:
25 Jul 2021, 19:28
Hi there,

the output is correct but I can't seem to get mine working:

Code: Select all

f12::Clipboard:=RegExReplace(RegExReplace(Clipboard, "\t?(\w\.)\t", "$1 "), "\R\t+", " ")

Also, will you know the answer to my other question on the different variations of the scripts?
Can't say for sure. Please, this time post the text, so I can check it. Thanks
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Can't get the correct regex output in Evernote

Post by milkygirl90 » 26 Jul 2021, 03:16

text posted

Code: Select all

Cannot find amount of shares that a company repurchased, only have the amount spent.
Outstanding shares actually increase instead of reducing in the quarter. Why?
a. In the 10k a company may have suspended their share repurchases for FY2020,
you can try referring to FY2019 10k reports to get some reference figures
The share repurchase price is incredibly low. Does this mean they only repurchased long time ago
(yr 2004)? Should I still put a +1 in FRIEDD SNAKE?
a. Share repurchase can start/stop anytime at the company discretion, it always advisable
to find the most recent annual/quaterly reports to get the updated figures, if the last
repurchase was many years ago, you may want to put a "O" in friedd snake to be
conservative
sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Can't get the correct regex output in Evernote  Topic is solved

Post by sofista » 26 Jul 2021, 07:48

Maybe I wasn't clear enough, please post the input text, the one that you want to process with regex. Thank you.
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Can't get the correct regex output in Evernote

Post by milkygirl90 » 26 Jul 2021, 17:20

sofista wrote:
26 Jul 2021, 07:48
Maybe I wasn't clear enough, please post the input text, the one that you want to process with regex. Thank you.
yes.. this is the input text to be processed:

Note this was the raw OCR output from ShareX using the input screenshot I shared earlier.

Code: Select all

1.
2.
Cannot find amount of shares that a company repurchased, only have the amount spent.
Outstanding shares actually increase instead of reducing in the quarter. Why?
a. In the 10k report, a company may have suspended their share repurchases for FY2020,
you can try referring to FY2019 10k reports to get some reference figures
The share repurchase price is incredibly low. Does this mean they only repurchased long time ago
(yr 2004)? Should I still put a +1 in FRIEDD SNAKE?
a. Share repurchase can start/stop anytime at the company discretion, it always advisable
to find the most recent annual/quaterly reports to get the updated figures, if the last
repurchase was many years ago, you may want to put a "O" in friedd snake to be
conservative
Output should look like this:

Code: Select all

1. Cannot find amount of shares that a company repurchased, only have the amount spent. Outstanding shares actually increase instead of reducing in the quarter. Why?
	a. In the 10k report, a company may have suspended their share repurchases for FY2020, you can try referring to FY2019 10k reports to get some reference figures

2. The share repurchase price is incredibly low. Does this mean they only repurchased long time ago (yr 2004)? Should I still put a +1 in FRIEDD SNAKE?
	a. Share repurchase can start/stop anytime at the company discretion, it always advisable to find the most recent annual/quaterly reports to get the updated figures, if the last repurchase was many years ago, you may want to put a "O" in friedd snake to be conservative
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Can't get the correct regex output in Evernote

Post by boiler » 26 Jul 2021, 18:31

How could the script know what separates the first paragraph from the second paragraph? There are no features that are likely repeatable enough for a script to know. In this particular block of text, the paragraph text preceding the "a." is two lines long in each case, but that is surely not to be counted on. There is nothing that would indicate where the text for the first "a." paragraph ends and the "2." paragraph begins. So what I'm saying is, there isn't enough information in the captured text to make it possible to write code to properly determine the paragraph break points for the general case. It could be written to combine this text the way you want only because we see in advance how it's suppose to be (and because we can read it as humans and determine the right break points), but it would not work for all cases unless they happened to all match the same number of lines, which I doubt would be the case.
sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Can't get the correct regex output in Evernote

Post by sofista » 26 Jul 2021, 19:00

I was about to write something similar to boiler's post, so I second what boiler wrote. Without more specific information, you can't make out a reproducible and reliable pattern.
Post Reply

Return to “Ask for Help (v1)”