Regex in Java

Reply

Join Date: Jun 2005
Posts: 23
Reputation: Rete is an unknown quantity at this point 
Solved Threads: 1
Rete Rete is offline Offline
Newbie Poster

Regex in Java

 
0
  #1
Oct 6th, 2005
Hi, I was wondering if anyone could help me with a problem I'm having in Java regarding Regex. All I'm trying to do (this is being dumbed down a bit) is scan a file, for specific text, and print it out. I'm trying to use regular expressions, but for some reason it isn't working the way it should.


		String regex = "(\\d+)";
		Pattern regexpat = Pattern.compile(regex);
		
		
			while (oneWord.hasMoreTokens()) {

				
				Matcher numFind = regexpat.matcher((CharSequence) oneWord.toString());

				boolean matchFind = numFind.find();
				if (matchFind = true) {
					System.out.println(oneWord.nextToken());
				}
			}

For testing sake, I'm using a really simple regular expression, but when I run the program, it prints out every single word in the text file. Does anyone know if I'm doing something wrong?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC