Page 1 of 1

From RegExMatch to RegExReplace

Posted: 27 Mar 2024, 11:52
by Billykid
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.

Re: From RegExMatch to RegExReplace

Posted: 27 Mar 2024, 12:42
by andymbody
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") 

Re: From RegExMatch to RegExReplace

Posted: 27 Mar 2024, 13:01
by Billykid
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.

Re: From RegExMatch to RegExReplace

Posted: 27 Mar 2024, 15:45
by andymbody
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).