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 $ query string, which is named $ text , to match the strings I'm going to use it for

Consider the following example (in PHP):

  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   

I can program a search function using the "traditional" approach:

  • Exhaust substrings and
  • Construction of tree of operation (priority)
  • Apply operators to the variable

    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 search function What does the search function do in your example?

    You can find out how regular expressions work if you do not understand them.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -