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. Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/ 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> Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-665193 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!! Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-665202 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. Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-665510 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! Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-665518 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? Link to comment https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-666100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.