php - Why does this preg_match not return 1? -


I'm looking at this code and it's about to match my $ input string and $ matches [0] store ' Test '

  $ input =': test '; $ R = Preg_Match ('/ ^ (? & Lt; = \ :).' / $, $ Input, $ matches);  

What's wrong with this?

(? & Lt; =) is a positive form - Back , which means that the pattern that corresponds to the attached expression should have parental status in the before pattern. In this case, this means that it should be after the start-by-string status ( ^ ), but first corresponds to all the characters before the actual character (. The string is here), and since : is the first real character, and there is no : before : (obviously), it Instead, use an capture group , which you might want to do, like:

  $ input = ' : Test '; $ R = preg_match ('/^:(.+)/', $ input, $ matches); The entire text in // $ matches [0] happens with the matching pattern, "test" // $ matches [1] will now include a "test" from the first capture  

this Type You use $ matches [1] to get the text from within the capture group, which you want.


Comments