Hello.

Can you tell me if I wrote the content quotation regular for quotes?

preg_match_all('/("|\')(.*)("|\')/iU', '0:1:2;;3:4:5:6:7;;8:"9,10,,","12,13",23:24;25:26;27:\'28\';;;14:15,16,17,18,19,20,21:22;;;', $matches); 

I am confused by one moment. Namely, the output is:

 Array ( [0] => Array ( [0] => "9,10,," [1] => "12,13" [2] => '28' ) [1] => Array ( [0] => " [1] => " [2] => ' ) [2] => Array ( [0] => 9,10,, [1] => 12,13 [2] => 28 ) [3] => Array ( [0] => " [1] => " [2] => ' ) ) 

I just got used to the fact that 2 values ​​are displayed, and here I have as many as 4. Is this how it should be, or did I get it wrong, as always?

  • one
    How many parentheses - so many values ​​+1 complete match. And I think the regular is not correct. .* captures every last quotation mark, if you need the closest ones better .*? and the choice of options from one symbol is easier to do in square brackets. total [\'"](.*?)[\'"] and there will be no unnecessary capture groups - Mike
  • @Mike, thank you, did not know that this affects the number of results. Displays 5 points. - dgd hsk
  • one
    @Mike there is a U modifier, so everything is fine. - ReinRaus
  • one
    /(["']).*?\1/ this is going to be so very good. - ReinRaus
  • one
    Because it is necessary to screen, and not just copy. I have given a regular expression how you put it in your program - only your decision. - ReinRaus

1 answer 1

It correctly displays - the array with the index 0 is all matches with the pattern pattern, the others are part of the pattern pattern that matches the pattern in brackets. since you have three parts of the values ​​in brackets, respectively, and 3 additional indexes. In the documentation, you can see how you can control the output using the flag

  • Thanks, I have a hard time with regulars. With the link you sent, I was familiar. I read it several times. - dgd hsk