It does not work to force a regular expression to accept only a period. In the line there is both a dot and an ellipsis (with it, both in the first and in the second case, "extra" spaces are possible): Это строка... Это строка . Это строка. Это строка... Это строка . Это строка. . I find the ellipsis as follows: "\\s*\\.{3}\\s*" . Then I try to find and replace all points like this: "\\s*\\.{1}\\s*" . As a result, I get the fact that the last expression finds single points and in ellipsis. How to exclude ellipsis for this expression?

  • Write more detailed and detailed questions with examples and what is already there. - And
  • one
    Try "\\s*(?<!\\.)\\.(?!\\.)\\s*" - Wiktor Stribiżew
  • @And, the code is not small. I tried to explain everything concisely. - UjinUkr
  • @ WiktorStribiżew, right .. write in the answer how it works if you are not hard. - UjinUkr

1 answer 1

You can use forward and backward preview blocks to find only those points in front of and behind which there are no other points:

 "\\s*(?<!\\.)\\.(?!\\.)\\s*" 

Here (?<!\.) Finds a match if there is no other point immediately before the point, and (?!\.) Checks if there is a point after the point that is located using the \. pattern \. .

See the regular expression demo .