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

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top