I have a code that looks for Regex matches and adds a new line after the regex Match. This works on the first click of a button, but when I click it again, it still captures the regex.
Example Scenario:
Change all sentences ending with 'dog.' and add a new line if it is not the end of the line.
Sample code inside mouse click event:
Pattern pattern = Pattern.compile("dog\\.(?!\n)");
Matcher matcher = pattern.matcher(paragraph);
paragraph = matcher.replaceAll("dog\\.\n");
Sample Input:
I found a street animal. It was a dog. Then the dog found another dog. It was kind of fun to see the two dogs barking to each other.
First click of button that implements code:
I found a street animal. It was a dog.
Then the dog found another dog.
It was kind of fun to see the two dogs barking to each other.
Second click of button that implements code:
I found a street animal. It was a dog.
Then the dog found another dog.
It was kind of fun to see the two dogs barking to each other.
I'm quite confused on why on the second click, it fails to notice that there is no more instance of 'dog.' without a new line.
Thanks in advance for the help!
Pattern pattern = Pattern.compile("dog\\.(?!\\n)");(?!\\r\\n)works, if the files uses CRLF\nto\r. Then this pattern should workdog\\.(?![\\n\\r])