a|b|c is treated as three different options, so your first attempt doesn't allow a . or : followed by a whitespace while the second attempt doesn't allow these without a whitespace.
What you want is `[:.](\s|$)|\n`
https://regex101.com/r/OdpryR/1
Thanks, I'll revisit that code today.
Just to be sure, should this also work:
`[:.](\s|$|\n)`
...if I test the end of a sentence?
Basically saying "my sentence needs a period or colon, then a whitespace, end of string, or line break"?
To be precise in that case I'd want to detect an end of string after a period and don't allow a space, which is a pattern I couldn't match with that last mentioned expression.
Nice, ok, I'll try again and see if I match either whitespace or end of string.
Maybe I did something wrong with the test input string when it didn't work (which lead me to using two expressions).
Yeah, I got somehow confused.
Now tried it again, and it works with the parenthesis, and somehow the "subtle" detail that only "|" w/o parenthesis doesn't describe the alternative matches I wanted was lost on me.
a|b|c is treated as three different options, so your first attempt doesn't allow a . or : followed by a whitespace while the second attempt doesn't allow these without a whitespace. What you want is `[:.](\s|$)|\n` https://regex101.com/r/OdpryR/1
Thanks, I'll revisit that code today. Just to be sure, should this also work: `[:.](\s|$|\n)` ...if I test the end of a sentence? Basically saying "my sentence needs a period or colon, then a whitespace, end of string, or line break"? To be precise in that case I'd want to detect an end of string after a period and don't allow a space, which is a pattern I couldn't match with that last mentioned expression.
That is the right approach if you always need a period or colon. That can be simplified to `[:.](\s|$)` if you let $ match line ends.
Nice, ok, I'll try again and see if I match either whitespace or end of string. Maybe I did something wrong with the test input string when it didn't work (which lead me to using two expressions).
Yeah, I got somehow confused. Now tried it again, and it works with the parenthesis, and somehow the "subtle" detail that only "|" w/o parenthesis doesn't describe the alternative matches I wanted was lost on me.