aspose file tools*
The moose likes Beginning Java and the fly likes java.util.regex package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.regex package" Watch "java.util.regex package" New topic
Author

java.util.regex package

Manoj Zachariah
Ranch Hand

Joined: Dec 08, 2003
Posts: 65
i just came across the Pattern and Matcher class in java.util.regex.
the code below gives me an error :
Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/CharSequence
Please help me out, thanks
//------------------
import java.util.regex.*;
import java.lang.*;
class pattern
{
public static void main(String[] args)
{
Pattern p = Pattern.compile("cat");
Matcher m = p.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, "dog");
result = m.find();
}
m.appendTail(sb);
System.out.println(sb.toString());
}
}
//--------------------
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
This code example compiles and runs fine on my system with Java 1.4 installed. Which version of Java are you using? You can find out by running java -version from a command prompt, if your PATH is configured properly.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Manoj Zachariah
Ranch Hand

Joined: Dec 08, 2003
Posts: 65
i'm using java version 1.3.1_01.
thanks for the reply
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Well the java.util.regex package wasn't part of Java 1.3. You'll need Java 1.4 or newer to use it.
[ December 10, 2003: Message edited by: Dirk Schreckmann ]
Manoj Zachariah
Ranch Hand

Joined: Dec 08, 2003
Posts: 65
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.regex package