$re = '/(#[0-9|a-f]{6})/m';
$str = 'const workInProgressRegex = /<[\\w]+[^>]*>.*?(#(?:[0-9a-fA-F]{3}){1,2})<\\/[\\w]+>/gim;
const exampleString1 = `<div><span class="foo" style="background-color: #ffffff;">#222222 foo #111111 abc #000000</span></div>`;
const exampleString2 = `<div><span class="foo" style="background-color: #ffffff;">"\'#222222 foo #111111 abc #000000</span></div>`;
const result1 = exampleString1.replaceAll(workInProgressRegex, "bar");
// should be `<div><span class="foo" style="background-color: #ffffff;">bar foo bar abc bar</span></div>`
const result2 = exampleString1.replaceAll(workInProgressRegex, "bar");
// should be `<div><span class="foo" style="background-color: #ffffff;">"\'bar foo bar abc bar</span></div>`';
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