-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
76 lines (63 loc) · 2.16 KB
/
Test.java
File metadata and controls
76 lines (63 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.verizon.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String args[]){
System.out.println("Hello world");
/* try {
// File file = new File("");
FileReader fr = new FileReader("C:\\Users\\Administrator\\Desktop\\DataHackathon\\inputsample.txt");
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null)
System.out.println(s);
fr.close();
}
catch(Exception e) {
System.out.println("Exception: " + e);
}
//
String filename = "C:\\Users\\Administrator\\Desktop\\DataHackathon\\output_sample1.txt";
String[] linesToWrite = new String[] { "a", "b" };
boolean appendToFile = true;
try{
PrintWriter pw = null;
if (appendToFile) {
pw = new PrintWriter(new FileWriter(filename, true));
} else {
pw = new PrintWriter(new FileWriter(filename));
// pw = new PrintWriter(new FileWriter(filename, false));
}
for (int i = 0; i < linesToWrite.length; i++) {
pw.println(linesToWrite[i]);
}
pw.flush();
pw.close();
}catch(Exception ex){
System.out.println("Ex "+ex);
}
}
*/
String var="more annoying";
//String REGEX = "\\b"+var+"\\b";
//String regEx = "([A-Z]+ [A-Z]+ [A-Z]+)";
//Pattern pattern = Pattern.compile(regEx);
//String regEx = "(\\sun[a-z]+)|(\\sdis[a-z]+)";
String regEx ="\\b[0-9][0-9]*\\stimes\\b";
String INPUT ="Arrived in a TIMELY FADH YOUTO. Plugged 6 times unwanted and disclosed works like a charm! No more annoying beeping from the old battery. After doing some homework, we found this price extremely affordable. ";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(INPUT); // get a matcher object
int count = 0;
while(m.find()) {
count++;
System.out.println("Match number "+count);
System.out.println("start(): "+m.start());
System.out.println("end(): "+m.end());
}
}
}