replace multiple occurances of string with a single string

R

ranumehta79

Hi,

I want to replace mulitple occurances of a string one after the another
with a single string

for eg .

input : a hello b world c java abcabcabc
output: a hello b world c java def

I mean multiple occurances of pattern 'abc' with a single string 'def'.


how can do this with JAVA regular expressions ?

I tried replaceAll method in string class, but I dont know how to
format regular expression.

thanks
Ranu
 
?

=?iso-8859-1?q?Fl=E1vio_Barata?=

Hi,

Try this piece of code:

"a hello b world c java abcabcabc".replaceAll("(abc)+", "def")

flavio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top