Regex in String.replaceall()

I wanted to remove ewg text from following lines completely.

ewg#First line

ewg#Second line

ewgThird line

For this i have used String class replace all method as follows:

StringBuffer sb =new StringBuffer(returnString.replaceAll("(?i)\\bentfw\\b",""));

The problem is this code is replacing only first two lines not the third line. Please help me

[473 byte] By [ArpanaKa] at [2007-10-3 4:02:24]
# 1
I don't see how it even removes 'ewg' from the first two lines! Don't you meanreturnString.replaceFirst("(?i)^ewg","")
sabre150a at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 2
> I don't see how it even removes 'ewg' from the first> two lines! Don't you mean> > returnString.replaceFirst("(?i)^ewg","")i am sorry that was a typing mistake . its supposed to be ewg
ArpanaKa at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 3
> returnString.replaceFirst("(?i)^ewg","")i tried this but its not removing ewg at all
ArpanaKa at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 4

> > returnString.replaceFirst("(?i)^ewg","")

>

> i tried this but its not removing ewg at all

Seems to work just fine for me:

String[] lines = new String[]{"ewg#First line", "ewg#Second line", "ewgThird line", "a line not starting with ewg"};

String regex = "(?i)^ewg";

for (String line : lines) {

System.out.println(line.replaceFirst(regex, ""));

}

JoachimSauera at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 5

> > > returnString.replaceFirst("(?i)^ewg","")

> >

> > i tried this but its not removing ewg at all

>

> Seems to work just fine for me:

>

> > String[] lines = new String[]{"ewg#First line",

> "ewg#Second line", "ewgThird line", "a line not

> starting with ewg"};

> String regex = "(?i)^ewg";

> for (String line : lines) {

> System.out.println(line.replaceFirst(regex, ""));

> }

>

sorry for long delay reply.

i still couldnt solve this problem.

i am not using any string array but a single string that separates these three lines with \n

ArpanaKa at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 6
sorry to bother but theres no one here who can show me solution to problem
ArpanaKa at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...
# 7

String] target =

"ewg#First line\newg#Second line\newgThird line\na line not starting with ewg";

String regex = "(?m)^ewg";

System.out.println(target.replaceAll(regex, ""));

http://www.regular-expressions.info/

uncle_alicea at 2007-7-14 22:01:48 > top of Java-index,Java Essentials,Java Programming...