Extract and validate search string before using it