Grego Posted December 17, 2007 Share Posted December 17, 2007 Preg Syntax confuses me - I'm just starting to learn it. Anyhow, I have this search term: "/\{INCLUDE\.*)\}/is" I want it to find {INCLUDE:sometext} on my page. However, my page has two of these statements on it: {INCLUDE:sometext} Bit in the middle {INCLUDE:othertext} So the preg_match is pulling out the following as a solution: sometext} Bit in the middle {INCLUDE:othertext How can I modify the syntax of "/\{INCLUDE\.*)\}/is" to make it only select the first following term, or only a solution before the end of a new line. If I haven't explained that well, please ask questions to determine the problem better. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
effigy Posted December 17, 2007 Share Posted December 17, 2007 Quantifiers are greedy by default. This means they take as much as possible and only backtrack to satisfy later matches. \{INCLUDE\: matches literally. (.*) gobbles up everything to the end of the string, then backtracks in order to match... \}, thus matching the last } in the string. Make the quantifier lazy, (.*?), or, even better, use ([^}]*). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.