php - How can ignore a string in quotes in this regex match? -


How can I ignore the examples of string "or" when inside single / double quotes?

The current expression is / ^ (? = \ $) (. +?) (?: \ S + or \ s +) (. +?) $ / S < / P>

Test value 1: $ test or "default value"

Test value 2: $ errors- & gt; Is ('email')? 'Error or failure': ''

Test value should affect 1, but value 2 should be unaffected.

Test Script:

To update $ expression .

  & lt ;? Php function issetDefaults ($ value) {// Original expression with problem // $ expression = '/ ^ (? = \ $) (. +)) ??? s = ++++++ (++) ) / S '; // @ Avinash Raj's version; Almost there; Test 2 $ has failed on expression = '/ ([\' 'altered] (??? :: ?? \\).) * Or (? :(?!? 1).) ****** **************************************************************************************************** ***). ^ (\ S +) or ([\ '"]. * [\'"]) / '; Return preg_replace ($ expression, 'provider ($ 2)' $ 2: $ 3 ', $ value);} // test $ Tests = array (//' $ test or 'default value' ',' $ age or 90 'Myfunc' (\ 'foo or bar \') should not be affected, '$ errors (' 'email' ')? \' Error or failure \ ': \' \ ',' $ errors- & ("Email")? "Error or failure": "" ',' $ Errors- & gt; ("email") "error" or "failure": "" '); // Output Test Foreign Currency ($ test as $ rate => $ test) {$ num = $ key 1; Anco '& lt; Strong & gt; Original value '. $ Num '& Lt; / Strong> Echo '& lt; Pre & gt; Print (Test $ true,). & Lt; / Pre & gt; '; Echo '& lt; Strong & gt; Values ​​'. $ Num. ' '& Lt; / Pre & gt; '; Echo '& lt; Hr / & gt; ';}  after work & lt; / Strong> 'Echo' & lt; Pre & gt; 'Print_r (issetDefaults ($ test)   

Regex string or Which would not match within the single or double quotes,

  ([?]) (?: (? !! 1).) Or (?: (?! \ 1 ). * 1 (* SKIP)  

Explanation:

  • ([']] capture ' or " symbols.
  • (?: (?! \ 1).) * does not match any characters that were previously captured in the group zero or more times .
  • or The string matches or .
  • (?: (?!! 1).) * is not a person who is in the first group
  • The first captured group was sent back through referenced.
  • ( * SKIP) (* F) creates the whole match to fail and which is | Following are the symbols ( \ bor \ b ) remaining part.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -