Basically I attempting to extract the last tag name of a handful of different css selectors.
I have successfully implemented what I am talking about in javascript, I'm looking for a more compact way using only 1 regex expression preferably.
Here is what I successfully have working.
//Trim selector, remove [attr] selectors due to conflicts, and standardize >,~,
selector=selector.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,'')
selector=selector.replace(/\[[^\]]*\]/g,'[]').replace(/\s*([>~\s])\s*/g,'$1');
var theSplit = selector.split(/[>~\s]/);
selector = /^[^.\[:]*/.exec(theSplit[theSplit.length-1]) || "*";
I am only looking to support css 2.0 selectors that are 100% supported by internet explorer 7.
For example + selector and :first-child selectors are static in ie7 and therefore I have no need to support them. Here is a list of css selectors that must work.
#test span ul a
#test >span[style="background:green"]
#id + span ~ article.class
section header.class
body
div
body div
div p
div > p
div ~ p
div[class^=exa][class$=mple]
div p a
.note
div.example
ul .tocline2
#title
h1#title
div #title
ul.toc li.tocline2
ul.toc > li.tocline2
a[href][lang][class]
div[class]
div[class=example]
div[class^=exa]
div[class$=mple]
div[class*=e]
div[class|=dialog]
div[class!=made_up]
div[class~=example]
Edit : I ended up using this script. It even takes into consideration the universal selector
var lastTagName = selector.replace(/\[[^\]]+\]|[\.#][\w-]+|\s*$/g,'').replace(/^.*[^\w]/, '')||'*'