DamienRoche Posted October 14, 2008 Share Posted October 14, 2008 Here's what I want to do with this. match everything between > and < - 1. can have space from beginning or end but cannot be a space and cannot be nothing (i.e. >< or > <) - 2. must be either a number or a word - number cannot end with . Here's my current regex with example string: <?php $str = ">< > < >123.< > 999 < >8,88< >eight< > eig.ht < >ni.ne< > nine <"; preg_match_all('#>.+?<#is', $str, $matches); print_r($matches); ?> desired output: Array ( [0] => Array ( [0] => > 999 < [1] => >8,88< [2] => >eight< [3] => > eig.ht < [4] => >ni.ne< [5] => > nine < ) ) I've had a bash but I can't figure it out. Would love your advice on it. Thanks. Any ideas are welcome. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 14, 2008 Share Posted October 14, 2008 With a flexible approach to a "number" or "word": <pre> <?php $str = '>< > < >123.< > 999 < >8,88< >eight< > eig.ht < >ni.ne< > nine <'; preg_match_all('#>\s*(?:[\d,.]+(?<!\.)|[a-z.]+)\s*<#is', $str, $matches); print_r($matches); ?> </pre> Quote Link to comment Share on other sites More sharing options...
DamienRoche Posted October 14, 2008 Author Share Posted October 14, 2008 Absolute genius! I'm gonna analyze that later so I can see exactly what's going on. Thanks!! Quote Link to comment Share on other sites More sharing options...
DamienRoche Posted October 14, 2008 Author Share Posted October 14, 2008 Hi, I've run into a little hiccup with this regex. it ignores anything that is in this format: 123.onetwothree it doesn't allow the number and the period in the same string. Is there a way to say only exclude those with . at the end? Thanks. Quote Link to comment Share on other sites More sharing options...
DamienRoche Posted October 14, 2008 Author Share Posted October 14, 2008 Sorry - I've *somehow* sussed it out myself. Thanks! Quote Link to comment Share on other sites More sharing options...
effigy Posted October 15, 2008 Share Posted October 15, 2008 must be either a number or a word - number cannot end with . How do you define a number or word? 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.