-2

So, I was messing around with regex to convert sentences into pig latin, and decided to extend the assignment to allow for punctuation. I was looking for a regex that allowed for me to replace the punctuation with an empty string and found myString.replaceAll("\\p{P}", ""); and was curious as to what the \p and {P} actually do here. Other similar questions have used "\\p{Z}" to replace whitespace, which leads me to think the \p is searching for whatever is inside of the brackets. Anyways any clarifications or directions to documentation would be much appreciated.

1 Answers1

1

In PCRE regular expressions

  • \p{P} is "Any punctuation character"
  • \p{Z} is "Any whitespace character"

See the "EXPLANATION" section on the right: https://regex101.com/r/ZFIKpv/1

Shamus
  • 66
  • 1