Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

check string equal with regex

I have a simple question.

How would i check if my string equals another string if that string has changing numbers at the end.

Random:1
Random (1):1
Random (2):1
Random (3):1
Random (4):1
So on...

and also with a string like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Random
Random_1
Random_2
Random_3
Random_4
So on...

>Solution :

You need std::regex_match and std::regex from <regex>:

#include <regex>

bool match(const char* cstr)
{
    static auto re = std::regex("Random \\([0-9]*\\):1"); // or whatever regex you'd like
    return std::regex_match(cstr, re);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading