944,117 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2059
  • Java RSS
Oct 6th, 2005
0

Regex in Java

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Rete is offline Offline
23 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Applet doesn't stop when switching page using frames.
Next Thread in Java Forum Timeline: jar in a jar?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC