Can you describe the semantics in prose? And I could help tweak the regex from there.