fix pattern regex to match begin & end