| | |
Regex - AND operator
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
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.
C++ Syntax (Toggle Plain Text)
#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(); }
Last edited by iamthwee; May 29th, 2009 at 4:57 am.
*Voted best profile in the world*
•
•
•
•
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
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
That's a well-known identity:
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++
C++ Syntax (Toggle Plain Text)
A and B <=> not (not A or not B)
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++
Last edited by ArkM; May 29th, 2009 at 8:37 am.
![]() |
Similar Threads
- using regex to replace a pattern? (C#)
- newbie: concatenating multiple RegEx's (Python)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- help with regex...and marking up text in JTextpane with html (Java)
- How to overload subscript operator? (C)
- Constructor and Convertion operator are the same,how to avoid memory leak? (C++)
Other Threads in the C++ Forum
- Previous Thread: drawing a line in visual c++v6.0
- Next Thread: how to convert text fine to bin file
Views: 519 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






