fork(2) download
  1. <?php
  2. $regex = '~
  3. (?P<address>[^,]+),\h+ # everything that is not a comma, followed by a comma and horizontal whitespace
  4. (?P<city>[^,]+),\h+ # the same as above
  5. (?P<state_zip>[^\n]+) # everything but a newline
  6. ~x'; # verbose mode
  7. $string = '555 Test Drive, Testville, CA 98773';
  8. preg_match($regex, $string, $match);
  9. echo $match["address"];
  10. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
555 Test Drive