Regex

Want to replace all char sequence starting with & and ending with ; to

a single letter # .

Tried the following but out put is :

test&atest#this &otest# string

Any idea / tutorial which can solve this problem ..

import java.util.regex.*;

publicclass StringTest

{

publicstaticvoid main(String args[])

{

String str ="test&atest;this &Otest; string";

String regex ="&*;";

String s = Pattern.compile(regex).matcher(str).replaceAll("#");

System.out.println(s);

}

}

[955 byte] By [CjavaVMa] at [2007-11-27 1:14:16]
# 1
Well, here is the [url= http://java.sun.com/docs/books/tutorial/essential/regex/]Java Regex Tutorial[/url].
Djaunla at 2007-7-11 23:49:36 > top of Java-index,Java Essentials,Java Programming...
# 2

public static void main(String args[])

{

String str = "test&atest;this &Otest; string";

String regex = "(&\\w+;)";

String s = str.replaceAll(regex,"#");

System.out.println(s);

}

mkoryaka at 2007-7-11 23:49:36 > top of Java-index,Java Essentials,Java Programming...