fork(1) download
  1. <?php
  2.  
  3. // your code goes here
  4. $regex = '{
  5. (?(DEFINE)
  6. (?<number> (?: -? (?: (?= [1-9]|0(?!\d) ) \d+ (?:\.\d+)? ) | \.\d+ ) )
  7. (?<variable> (?: \bM\b ) )
  8. (?<clause> (?:
  9. (?&variable) \s* [<>=] \s* (?&number) |
  10. (?&variable) \s+ between \s+ (?&number) \s+ and \s+ (?&number)
  11. ))
  12. )
  13. (?&clause)
  14. }x';
  15.  
  16. $str = '(a > 3) and ( b + c = 4 and M < 4) and (d + e = 6 and M between 4 and 6) and z>10';
  17. if (preg_match_all($regex, $str, $matches)) {
  18. foreach ($matches[0] as $m) {
  19. echo $m. PHP_EOL;
  20. }
  21. }
Success #stdin #stdout 0.01s 24480KB
stdin
Standard input is empty
stdout
M < 4
M between 4 and 6