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?
|
1 answer
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 .
|
"\\s*(?<!\\.)\\.(?!\\.)\\s*"- Wiktor Stribiżew