Update test2.php

- More simpler and optimised code
- Better pattern matching