I'm trying to remove single and double quotes from html attributes that are single words with no white spaces. I wrote this regex which does work:
/((type|title|data-toggle|colspan|scope|role|media|name|rel|id|class|rel)\s*(=)\s*)(\"|\')(\S+)(\"|\')/ims
How ever instead of specifying all the html tags that I want to remove the quotes on, I rather just list the couple attributes to ignore like src and href and remove the quotes on all other attribute names. So I wrote the one below but for the life of me it doesn't work. It some how has to detect any atribute name except the href and src. I tried all kinds of combinations.
/((?!href|src)(\S)+\s*(=)\s*)(\"|\')(\S+)(\"|\')/i
I've tried this but it doesn't work. it just removes the h and s off the attribues for href and src. I know I'm close but missing something. I spent a good 5 hours on this.
working example
$html_code = 'your html code here.';
preg_replace('/((type|title|data-toggle|colspan|scope|role|media|name|rel|id|class|rel)\s*(=)\s*)(\"|\')(\S+)(\"|\')/i', '$1$5', "$html_code");