hlstriker Posted October 18, 2008 Share Posted October 18, 2008 I'm trying to check to see if the start of a new line isn't a { bracket. Here is the file layout I'm searching: { Bracket line 1 } { Bracket line 2 } { Bracket line 3 } This line is not in brackets And here is the pattern I'm using: preg_match("~{\n\".*(?=}\n[^{])~msU", $string, $match); So, I'm trying to get all the lines in brackets until there is not a new starting bracket. For some reason the [^{] part of the pattern seems to be the problem. Quote Link to comment https://forums.phpfreaks.com/topic/128933-check-if-start-of-new-line-is-not/ Share on other sites More sharing options...
ghostdog74 Posted October 18, 2008 Share Posted October 18, 2008 don't have to be that complicated, here's one without the much regexp. split the file on closing braces. Check each value and display them if there is opening braces. $file="file"; $data = file_get_contents($file); $data = split("}",$data); foreach ($data as $k=>$v){ if( strpos($v,"{") !== FALSE){ echo "$v\n"; } } output: # ./test.php { Bracket line 1 { Bracket line 2 { Bracket line 3 tested only on your supplied data. Quote Link to comment https://forums.phpfreaks.com/topic/128933-check-if-start-of-new-line-is-not/#findComment-668470 Share on other sites More sharing options...
JasonLewis Posted October 18, 2008 Share Posted October 18, 2008 What about this? $string = <<<html { Bracket line 1 } { Bracket line 2 } { Bracket line 3 } This line is not in brackets html; preg_match_all("#{(.*?)}#is", $string, $matches); echo "<pre>", print_r($matches[1]), "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/128933-check-if-start-of-new-line-is-not/#findComment-668471 Share on other sites More sharing options...
nrg_alpha Posted October 18, 2008 Share Posted October 18, 2008 preg_match_all("#{(.*?)}#is", $string, $matches); You don't need the i modifier, as you are using the wildcard as the matching criteria. Alternatively, instead of using a wildcard and a lazy quantifier, you can use a negated character class: preg_match_all("#{([^}]+)}#", $string, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/128933-check-if-start-of-new-line-is-not/#findComment-668629 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.