| | |
Regex in Java
![]() |
•
•
Join Date: Jun 2005
Posts: 23
Reputation:
Solved Threads: 1
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.
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?
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
- xml parsing from java (Java)
- my project is IDE for java (Java)
- help with regex...and marking up text in JTextpane with html (Java)
- Java Expert (Needed) (Java)
Other Threads in the Java Forum
- Previous Thread: Applet doesn't stop when switching page using frames.
- Next Thread: jar in a jar?
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows





