J
jagonzal
Hi,
I'm trying to find instances of a period separating two words with no
space within a string, and replace such periods with a space. For
example, if I give it this string:
"I'm a string. With.some.period.separated.words"
it should return
"I'm a string. With some period separated words"
The first period stays because there was a space to its right. The
other ones are replaced.
I tried doing this:
String filteredString = originalString.replaceAll("(\\S)\\.(\\S)","\1
\2");
This results in: "I'm a string. Wit* *om* *erio* *eparate* *ords", the
asterisks denoting non-existing characters in the printing font
(unicode 1 and 2?)
Then I tried this, supposing I was not escaping the back references to
the capturing groups correctly:
String filteredString = originalString.replaceAll("(\\S)\\.(\\S)","\1
\2");
This results in: "I'm a string. Wit1 2om1 2erio1 2eparate1 2ords"
Anybody spot what am I doing wrong?
Thanks in advance,
Javier.
I'm trying to find instances of a period separating two words with no
space within a string, and replace such periods with a space. For
example, if I give it this string:
"I'm a string. With.some.period.separated.words"
it should return
"I'm a string. With some period separated words"
The first period stays because there was a space to its right. The
other ones are replaced.
I tried doing this:
String filteredString = originalString.replaceAll("(\\S)\\.(\\S)","\1
\2");
This results in: "I'm a string. Wit* *om* *erio* *eparate* *ords", the
asterisks denoting non-existing characters in the printing font
(unicode 1 and 2?)
Then I tried this, supposing I was not escaping the back references to
the capturing groups correctly:
String filteredString = originalString.replaceAll("(\\S)\\.(\\S)","\1
\2");
This results in: "I'm a string. Wit1 2om1 2erio1 2eparate1 2ords"
Anybody spot what am I doing wrong?
Thanks in advance,
Javier.