Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.regex package

 
Manoj Zachariah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manoj Zachariah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm using java version 1.3.1_01.
thanks for the reply
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic