hi ,
can anyone tell how to define AND operator by regular expression.

Actually I want to return match if and only if 2 substrings will appear in string.

For example i have string "Successful Logon: User Name: Administrator Domain: Logon ID: (0x0,0x154CB759) Logon Type:2 Logon Process: Advapi Authentication Package: MICROSOFT_AUTHENTICATION_PACKAGE_V1_0 Workstation Name: LC2KEDS1"

and match should be return only for Administrator and Logon Type:2 if anyone of this found match should not return
it only return when both will be there

Yeah that's pretty simple, you could just use string find twice.

#include <iostream>
#include <string>

int main()
{
    std::string t = "Administrator blah blah logon:2 blah blah";
    
    int matchOne = t.find("Administrator");
    int matchTwo = t.find("logon:2");
    
    //std::cout << matchOne << std::endl;
    //std::cout << matchTwo;
    
    if (( matchOne >= 0 ) && ( matchTwo >= 0 ))
    {
      std::cout<<"Found";
    }
    
    std::cin.get();
}

Something like:

^.*Administrator.*Logon Type:2.*$

should do the job.

this expression selects all words between administrator and Logon Type:2

Regex doesn't exist in c++.

Unless you're using boost libraries or C++/cli/.net, you already have a solution post #2. There is no need to use regex here. If you need to use it, please give us a reason why.

Regex doesn't exist in c++.

Unless you're using boost libraries or C++/cli/.net, you already have a solution post #2. There is no need to use regex here. If you need to use it, please give us a reason why.

I am using PCRE library for using regular expression in c++ application.
second solution is fine but doing 2 findings and finally apply && operator in if condition will increase overhead.

I want this as a single regular expression and after APIs of PCRE library will do the stuff. PCRE (Perl Compatible Regular Expressions) is an open source library written in C that allows developers to add regular expression support in c/c++ application

You still haven't answered why post #2 isn't an adequate solution though. Using regex is far more expensive in terms of overhead so your argument is BS.

You still haven't answered why post #2 isn't an adequate solution though.

second solution is fine but doing 2 findings and finally apply && operator in if condition will increase overhead.

There is no need to use regex here. If you need to use it, please give us a reason why.

Reread the article of the TO carefully.

Comments
yes will do

That's a well-known identity:

A and B <=> not (not A or not B)

As far as I know there are not and or operators in all versions of regular expressions...

Remark on post#2: string::find returns unsigned value. It's a bad practice to assign it to int variables then test if it's less than 0 (see std::basic_string::npos constant value)...
None the less it looks like the fastest solution in C++ ;)

This article has been dead for over six months. Start a new discussion instead.