php - Building a regex from a set of logical expressions -
I have created a simple grammar for logical expressions, using boolean operators and stars as their operand, which I want to pass as a URL query string I present it in another string in the Consider the following example (in PHP): I can program a search function using the "traditional" approach: Although I believe that less and Amp; Fast way using REGEX If you know enough regex to give practical help, please help. Thanks! You probably do not need to type the You can find out how regular expressions work if you do not understand them. $ query string, which is named
$ text , to match the strings I'm going to use it for
function search ($ text, $ query) // $ text, $ query string {// returns true If the logical expression is generated from the $ query $ true for the test string // otherwise the wrong result returns $ query: // query contains $ 1 (variable) variable between parentheses and operators: // (2) Operators are: & amp; = And, | = Or,! = No // (3) The priority of the logical functions is defined by the parenthesis: () // (4) variable = true if substring is present in $ text, then it is not wrong /} Example: $ text1 = 'str4 str3 Blalbablastr2 '; $ Text2 = 'str4whichherere str3str5'; // str5 current or str1 exists $ simpleQuery = 'str5 | str1 '; // present (str1 or str2), (str3 present), and (str4 current or str5 not present) $ complexCatai = '(str1 | str2) & str3 & amp; (Str4 | | str5) '; Search ($ lesson 1, $ simplicity); Returns incorrect as' // 'str5' or 'str1' = false search ($ lesson 2, $ simplicity); // True Returns as 'str5' / True Search ($ lesson 1, $ complexity); // True Returns as 'str2' and 'str3' and ('str4' and 'str5') = true search ($ lesson 2, $ complexity); // Return error 'str1' or 'str2' = false
search function What does the search function do in your example?
Comments
Post a Comment