I have the following regular expression in java -
Pattern p = Pattern.compile("int|float|char\\s\\w");
But still this is matching "intern
" too .
entire code -
package regex;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Regex {
public static void main(String[] args) throws IOException{
// TODO code application logic here
int c = 0;
BufferedReader bf = new BufferedReader(new FileReader("new.c"));
String line;
Pattern p = Pattern.compile("int|float|char\\s\\w");
Matcher m;
while((line = bf.readLine()) != null) {
m = p.matcher(line);
if(m.find()) {
c++;
}
}
System.out.println(c);
}
}