Regular Expression to find merge conflicts in file

This is the file which contains merge conflicts,

<<<<<<< HEAD
$conf['some_unit_id'] = '4-qw-gg-ds-sometext';
=======
// Some Snippets Site Info
$conf['site_info'] = array(
  'customer_service_phone' => '+1 323223232
  'logo_path' => 'https://www.google.com/img/icons/src/logo.svg',
  'currency' => 'CAD',
    'https://www.youtube.com/user/somewebsite/ogog',
    'https://www.instagram.com/somewebsite/',
  ),
);
>>>>>>> ff6df3435231fdff78fwsd83e7dffa0732eft554

// Somes code
$done['rules'] = TRUE;

Am trying to find the best regular expression that detect merge conflicts in the file. Initially I tried with :

/(<* HEAD)/

Which will detect only HEAD with some preceding < I have some other markers as well like :

1. ======
2. >>>>> ff6df3435231fdff78fwsd83e7dffa0732eft554

These two markers must detect along with HEAD marker as well. And if a developer fixes the merge conflicts only <* HEAD and rest of the ie., ===== and >>> ff6df3435231fdff78fwsd83e7dffa0732eft554 the regular expression should detect that as well.

Since this regular expression am using in pre-commit hook. If one pattern detected in file commit will break. I need exact regex to detect merge conflict markings.

Any solution would be appreciated.

Answer

Since they’re all the same length, you can use a character group:

/^[<=>]{7}( .+)?$/mg

(make sure to use a multiline regex)