-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regular_expression_searching.cpp
84 lines (69 loc) · 1.52 KB
/
Regular_expression_searching.cpp
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
77
78
79
80
81
82
83
84
#include<algorithm>
#include<cstring>
#include<iostream>
#include<fstream>
using namespace std;
bool validity_of_string(string str ,string reg_exp) /* STANDARD REGEX FORM */
{ // (b).(a+b)*.(ab)* // (a)*.(ab).(b)*
bool star=false,dot=false,plus=false;
star=contains_star(str);
dot=contains_dot(str);
plus=contains_plus(str);
if(str[1]!=reg_exp[0] && reg_exp[])
{
return true ;
}
return false;
}
bool contains_star(string &s)
{
if (s.find('*') != string::npos)
{
return true;
}
return false;
}
bool contains_dot(string s)
{
if(s.find('.') != string::npos)
{
return true;
}
return false;
}
bool contains_plus(string s)
{
if(s.find('+') != string::npos)
{
return true;
}
return false;
}
int count_alphabet_A(string str)
{
size_t n = std::count(str.begin(), str.end(), 'a');
return n;
}
int count_alphabet_B(string str)
{
size_t n = std::count(str.begin(), str.end(), 'b');
return n;
}
int main()
{
cout<<"Enter the regular Expression \n"; // STANDARD REGEX FORM // (b).(a+b)*.(ab)* // (a)*.(ab).(b)*
string reg_exp;
cin>>reg_exp;
cout<<"Matched string with the given regular expressions are "<<endl;
ifstream fin;
fin.open("input.txt");
while(!fin.eof())
{
string str;
fin>>str;
if(validity_of_string(reg_exp,str))
cout<<str<<endl;
}
fin.close();
return 0;
}