I am trying to do the following regex copy_Reduced := RegExReplace(copy_M, "m`a)\s*\R\s*", " __ ")
I am "expecting output with all newlines (and surrounding \s*) removed"
## problem-arise_problem
The result shows it does not match anything.
- (in PCRE regex101 it does work as expected, in Ahk it does not)
Why is that?
## problem-other_ways_that_produce_expected_result__but_not_understood
It only works if I replace \R
with `n (can have / not have `a option)
or with $\R (must have `a option)
(Why is that?)
## problem-ex_code
Code: Select all
^r::
copy_M =
(
this is a testing string
one-shot
more paragraphs 1
more paragraphs 2
)
; with `a #####
copy_Reduced := RegExReplace(copy_M, "m`a)\s*\R\s*", " __ ") ; Wrong, expecting output with all newlines (and surrounding \s*) removed <<<<<
displayAhkOutputWindow(copy_Reduced)
copy_Reduced := RegExReplace(copy_M, "m`a)\s*`n\s*", " __ ") ; Ccorrect
displayAhkOutputWindow(copy_Reduced)
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m`a)\s*`r`n\s*", " __ ") ; Wrong
; ;ignore; displayAhkOutputWindow(copy_Reduced)
; ;ignore;
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m`a)\s*`r\s*", " __ ") ; Wrong
; ;ignore; displayAhkOutputWindow(copy_Reduced)
copy_Reduced := RegExReplace(copy_M, "m`a)\s*$\R\s*", " __ ") ; Correct
displayAhkOutputWindow(copy_Reduced)
copy_Reduced := RegExReplace(copy_M, "m`a)\s*$`n\s*", " __ ") ; Correct
displayAhkOutputWindow(copy_Reduced)
copy_Reduced := RegExReplace(copy_M, "m`a)\R", " __ ") ; Correct (just for compare)
displayAhkOutputWindow(copy_Reduced)
; with no `a #####
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\s*\R\s*", " __ ") ; Wrong
; ;ignore; displayAhkOutputWindow(copy_Reduced)
; ;ignore;
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\s*`n\s*", " __ ") ; Correct
; ;ignore; displayAhkOutputWindow(copy_Reduced)
; ;ignore;
; ;ignore; ; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\s*`r`n\s*", " __ ") ; Wrong
; ;ignore; ; ;ignore; displayAhkOutputWindow(copy_Reduced)
; ;ignore; ; ;ignore;
; ;ignore; ; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\s*`r\s*", " __ ") ; Wrong
; ;ignore; ; ;ignore; displayAhkOutputWindow(copy_Reduced)
copy_Reduced := RegExReplace(copy_M, "m)\s*$\R\s*", " __ ") ; Wrong (when `a is not used)
displayAhkOutputWindow(copy_Reduced)
; ;ignore;
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\s*$`n\s*", " __ ") ; Wrong
; ;ignore; displayAhkOutputWindow(copy_Reduced)
; ;ignore;
; ;ignore; copy_Reduced := RegExReplace(copy_M, "m)\R", " __ ") ; Correct (just for compare)
; ;ignore; displayAhkOutputWindow(copy_Reduced)
return
; [Outputs, printed by displayAhkOutputWindow()] #########
output =
(
this is a testing string
one-shot
more paragraphs 1
more paragraphs 2
2 >>>>>
this is a testing string __ one-shot __ more paragraphs 1 __ more paragraphs 2
3 >>>>>
this is a testing string __ one-shot __ more paragraphs 1 __ more paragraphs 2
4 >>>>>
this is a testing string __ one-shot __ more paragraphs 1 __ more paragraphs 2
5 >>>>>
this is a testing string __ one-shot __ more paragraphs 1 __ more paragraphs 2
6 >>>>>
this is a testing string
one-shot
more paragraphs 1
more paragraphs 2
)