Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want regular expression small_letter(small_letter,small_letter);
input:like(sara,bola);
output:atomic

input:like(sara,Bola);
output:other


C++
#include<iostream>
#include<string>
#include<regex>
using namespace std;
int main()
{
    string s ;
    cout << "Enter a sentence to check: ";
    std::getline(cin, s);
    
    regex re("^(a-z)+\(+(a-z)+\,+(a-z)+\) $");
    bool m = regex_match(s,re);
    
    cout <<( m ? "atomic":"other") << endl;
    system("pause");
    return 0;
}
Posted
Updated 15-Nov-15 4:48am
v3
Comments
George Jonsson 14-Nov-15 23:45pm    
I guess you mean small letter and not small litter

1 solution

You have a syntax error in your expression. You are using ( instead of [.
So change the expression from
^(a-z)+\(+(a-z)+\,+(a-z)+\) $

to
^[a-z]+\(+[a-z]+\,+[a-z]+\);$

I also replaced the white space with a ;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900