I want to make sure that the substring I am matching only has one possible piece of punctuation and as much whitespace as necessary. This is inside of a much longer REGEX, currently what there is is the following:
[\p{P},\s]
but that will match all punctuation and whitespace, so that it accepts:
the string before,,,, ,,,. ....the string after when what I want it to match is any amount of whitespace in between the string before and the string after, with only one item of punctuation allowed- note that the punctuation can come at the beginning of the string, at the end, or with as much whitespace before or after.
what I want it to match is any amount of whitespace in between the string before and the string after, with only one item of punctuation allowed
Try this:
\s*\p{P}\s*
Explanation:
\s* Match any amount of whitespace \p{P} Match a single punctuation character \s* Match any amount of whitespace
Note that in Java string literals the backslashes need escaping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With