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]

> > 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, ""));
}
> > > 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
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/