Paul Clapham wrote:Well, in line 11 of that code you apply replaceAll to the input string (variable name w) and assign the result to a new variable named wnew.
Then at line 12 you apply replaceAll to the input string again, only with a different regex, and assign that result to the variable named wnew. This has the effect of discarding the result of line 11.
Anyway, with regex there's all kinds of unexpected things which can happen if you get it a bit wrong. So it would help if you showed us an example of an input string and the result of line 12. Also it would help if you told us what you expected instead.
Campbell Ritchie wrote:There must be easier ways to do that, even with a regex. Have you come across the predefined character class \w?
To misquote Edsger Dijkstra, It is impossible to show correctness by testing, only incorrectness.
William Ng wrote:. . . I have tested its correctess at regexpal.com. . . . .
Campbell Ritchie wrote:
You can pass the entire line to a Scanner object, then you can get a Stream of matches from a regex. Look at this method. (Java9 only.) Use its return result's group() method to get a String, and the last line simply calls System.out.println():-
. . . which is why you aren't matching the ellipses.
Rob Spoor wrote:. . . $[.]+ will never match anything.
Try "[\\w|']+" instead.
A few minutes ago, I wrote:\\w won't find the apostrophe.
Rob Spoor wrote:Side note: since $ matches the end of the string, $[.]+ will never match anything.
Campbell Ritchie wrote:Where I am sitting, FA means something else and you wouldn&apost find it to work. Please avoid such abbreviations.