-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularExpression.java
More file actions
50 lines (43 loc) · 1.45 KB
/
RegularExpression.java
File metadata and controls
50 lines (43 loc) · 1.45 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
import java.util.*;
public class RegularExpression {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String s = new String();
String p = new String();
String p_mod = "";
s = sc.nextLine();
p = sc.nextLine();
int plen;
int flag =0;
char ch;
int len = p.length();
for(int i= 0; i<len; i++){
ch = p.charAt(i);
if(ch== '*' && flag == 0 && p.indexOf('.') == -1){
System.out.println("true");
flag=1;
break;
}
else if(ch== '*' ){
continue;
}
else if(ch == '.' && p.indexOf('.')!= -1 && flag == 0 ){
plen = p_mod.length();
for(int j = 0; j <= s.length() - plen ; j++){
// System.out.println(s.substring(j, j+plen));
if(p_mod.compareTo(s.substring(j, j+plen)) == 0 && flag == 0 ){
System.out.println(true);
flag=1;
break;
}
}
}
else{
p_mod = p_mod + ch;
}
sc.close();
}
if(flag==0)
System.out.println("false");
}
}