fixed regex to handle () inside $ references