updated regex and added conditions