954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regex in Java

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.

<strong>String regex = "(\\d+)";
		Pattern regexpat = Pattern.compile(regex);</strong>
		
		
			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?

Rete
Newbie Poster
23 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You