Implemented following changes :

1. Make regex variable global.
2. Used operator '&' instead of "&&".