Find second punctuation mark in the middle of the line

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

Find second punctuation mark in the middle of the line

Post by Billykid » 19 Apr 2024, 14:07

All lines end at the end of their line with a punctuation mark, i.e. a period.
Some lines have a second sentence in the line. The corresponding
punctuation mark is somewhere in the middle of the line.
I am looking for a RegExMatch expression that finds and displays this line.


Example:

Code: Select all

str := "This is a simple sentence!`nThis is a second sentence in line two.`nThis is also a sentence. You should find this line of text!`nLine_Next.`nLine_Next."
Here the line:

Code: Select all

This is also a sentence. You should find this line of text!
must be found.

User avatar
Datapoint
Posts: 311
Joined: 18 Mar 2018, 17:06

Re: Find second punctuation mark in the middle of the line

Post by Datapoint » 19 Apr 2024, 15:02

One of these maybe:

Code: Select all

str := "This is a simple sentence!`nThis is a second sentence in line two.`nThis is also a sentence. You should find this line of text!`nLine_Next.`nLine_Next."

;RegExMatch - find the second sentence on one line
RegExMatch(str, "[!.?]\h\K[^\v]+", match)
MsgBox % match

;RegExMatch - find the entire line with two sentences
RegExMatch(str, "m`a)^.+[!.?]\h[^\v]+", match)
MsgBox % match

;RegExReplace - one sentence per line
MsgBox % RegExReplace(str, "[!.?]\K\h([^\v])", "`n$1")

Post Reply

Return to “Ask for Help (v1)”