$re = '/\[data-testid=([^\]]*?)\](?!.*\[data-testid=.*?\])/m';
$str = '@header;.header-area;.sticky;|@div;.container;|@div;.row;|@div;.col-lg-12;|@nav;.navbar;.navbar-expand-lg;|@div;#navbarSupportedContent;.collapse;.navbar-collapse;|@ul;#nav;.ml-auto;.navbar-nav;|@li;.active;.nav-item;|@a;[data-testid=foo];[href=#service];|
@section;#contact;.contact-area;.pt-115;|@div;.container;|@div;.contact-box;.mt-70;|@div;.row;|@div;.col-lg-8;|@div;.contact-form;|@form;#contact-form;[data-toggle=validator];[method=post];|@div;.row;|@div;.col-lg-12;|@div;.form-group;.single-form;|@button;.main-btn;[type=submit][data-testid=bar];|';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php