Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Seemingly simple, yet annoying reg. expression issue

807588Jan 19 2009 — edited Feb 2 2009
Hey guys,

Im considerably familiar with the use of regular expressions in Java (and other languages), yet seem to be having a very simple problem.

I wish to match a full stop character occuring after a space in a string, once that space does not occur after a digit.

e.g. "went to the shop . This is another sentence"

The code I'm using is this:
String s = "went to the shop. This is another sentence"
s = s.replaceAll("([^0-9]+)\\s+\\.","$1.");
This doesn't seem to work, neither does:
String s = "went to the shop. This is another sentence"
s = s.replaceAll("(\\D+)\\s+\\.","$1.");
It seems that there's a problem with the first + symbol, but I'm not sure exactly what the problem is.

Any insights?

Edited by: SuperGrover on Jan 19, 2009 12:35 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2009
Added on Jan 19 2009
11 comments
179 views