PHP complex regex -


If you have some time for me, then my problem is:


Example string :

  {= $ test-> {$ Test- & gt; Exam} () "This is a test" {= $ Test2-> {$ Test2- & gt; Examination} () "This is another test" ("}" Chilo has been found once again. According to consultation and consultation the affiliates have been included. {= $ Test3} {= $ test-> gt; {$ Test-> {$ test-> Exam}} () "This is an exam" {= $ Test2-> {$ test2-> Exam} () "This is another test "{}: {}} Chile has been found once again, according to consultation and consultation the affiliates have been included. Example of expected results with the  preg_match_all  function:  < Ul > 
  • $ test -> {$ test-> test} (). "This is an exam" (
  • $ test2 -> {$ test2-> test} () "This is another test
  • $ test3

    I need to find all between "{=" and "}";

  • "{}" Is found in the form of a pair
  • However, it may be authorized:
    • "{" A single quotation and "double" bonus, " I am using this expression: {code> / {= (\?)? ([^}] +)}

      / P>

      I try: / {= \ s + (({{^}} *}). [^}] +) [^}] *} / X but its wrong result is:

      Thank you for your help.

  • You can create a pattern that is {= and } :

      $ describes the potential elements between patterns = & lt; & Lt; & Lt; 'EOD' ~ (? (Define) (? Citation & gt; '(? & Gt; [^' \\] ++ | \\.) * '' '(? & Gt; [^ " \] ++ | \\.) * ") (? & Lt; curly & gt; {(? & Gt; \ g  quotes & gt; | g & lt ; Curly & gt;) *}} (? & Lt; other & gt; [^ {}} ''] ++)} {= (? & Gt; \ g  quotes & gt; | gg & lt; curly & gt;) *} ~ xs EOD; preg_match_all ($ patterns, $ str, $ matches); print_r ($ matches [0]);  

    (DEFINE) ...) section of the pattern As you would use later on bricks, you can define any characters without the designated subclasses. . (& lt ;? Name & Gt; ...) defines a nominated subpot you can call \ g Name & gt; anyway.

    About the "crisp" of the main pattern (which characters use) {= (? & Gt; \ g

    "quote" and "other" :; \ G | gg

    For easier read but "curly", the potential content between curly brackets Recursive call to handle nested curly brackets uses it.

    Note: This pattern works because curly brackets are balanced, but if it is not there then unexpected results will result in litigation. However, to deal with unbalanced curly brackets, you can change the pattern like this:

      ~ (? (DEFINE) (? & Quot; citation & gt; '(? & Gt; [^ '\\] + + | \\.) *' | "(? & Gt; [^ \\] ++ | \\.) *") (? & Lt; curly & gt; {(? & Gt; \ g  | G  | g \ l> curly & gt; |)}} (? & Lt; Other & gt; [^ {}) '' ] ++)) {= (? & Gt; \ g  Other & gt; | g  citation & gt; | g & lt; curly & gt; | {} *} ~ xs  

    Comments

    Popular posts from this blog

    import - Python ImportError: No module named wmi -

    Editing Python Class in Shell and SQLAlchemy -

    c# - MySQL Parameterized Select Query joining tables issue -