From RegExMatch to RegExReplace

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Billykid
Posts: 98
Joined: 16 Sep 2019, 08:59

From RegExMatch to RegExReplace

Post by Billykid » 27 Mar 2024, 11:52

Hi,

I find my matches with this:

Code: Select all

RegExMatch(strText, "\n[A-Z]\s*[A-Za-z\s]*\n", match)
these matches should be replaced

Code: Select all

strText := RegExReplace(strText,  "\n[A-Z]\s*[A-Za-z\s]*\n",  ????)  ; What does the code look like if I just want insert a single dot before the right line break?

as a replacement I just want to insert a single dot before the line break on the right side.

Code: Select all

"\n[A-Z]\s*[A-Za-z\s]*   .         \n"


What does the correct strReplace formula look like?
A cordial thanks for your help.

User avatar
andymbody
Posts: 904
Joined: 02 Jul 2017, 23:47

Re: From RegExMatch to RegExReplace

Post by andymbody » 27 Mar 2024, 12:42

Try this... but, keep in mind that your needle won't support carriage return if it is also part of strText. I personally like to use \h instead of \s for horizontal whitespace. But I chose not to alter any of your original needle.

Code: Select all

strText := RegExReplace(strText,  "(\n[A-Z]\s*[A-Za-z\s]*)(\n)",  "$1\.$2") 

Billykid
Posts: 98
Joined: 16 Sep 2019, 08:59

Re: From RegExMatch to RegExReplace

Post by Billykid » 27 Mar 2024, 13:01

Unfortunately not.
I already tried this:

Code: Select all

str := RegExReplace(str, "(\A|\n)([A-Z]\s*[A-Za-z\s]*\n)", "$1.$2")
But the dot is then at the beginning of the line and not at the end.

User avatar
andymbody
Posts: 904
Joined: 02 Jul 2017, 23:47

Re: From RegExMatch to RegExReplace

Post by andymbody » 27 Mar 2024, 15:45

Billykid wrote:
27 Mar 2024, 13:01
But the dot is then at the beginning of the line and not at the end.
Your needle is different than the one I posted.
strText := RegExReplace(strText, "(\n[A-Z]\h*[A-Za-z\h]*)(\n)", "$1.$2")

(I accidentally included the escape char with the dot in my original replacement).

Post Reply

Return to “Ask for Help (v1)”