正则表达式中验证原子的问题 [英] problem in regular expression to validate atomic

查看:87
本文介绍了正则表达式中验证原子的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要正则表达式small_letter(small_letter,small_letter);

输入:喜欢(sara,bola);

输出:原子



输入:喜欢(sara,Bola);

输出:其他





I want regular expression small_letter(small_letter,small_letter);
input:like(sara,bola);
output:atomic

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


#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;
}

推荐答案

);
bool m = regex_match(s,re);

cout<<(m? atomic other)<< endl;
system( pause);
返回 0 ;
}
"); bool m = regex_match(s,re); cout <<( m ? "atomic":"other") << endl; system("pause"); return 0; }


你有一个表达式中的语法错误。你正在使用(而不是[。

所以改变表达式来自

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


to

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


这篇关于正则表达式中验证原子的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆