javascript how to preg match first word and last word from html?
for example, in the below sentence, I want get words The and underway. Thanks.
<p>The Stack Overflow 2011 community moderator election is underway</p>
//should consider the different html tags.
If the element is already in the document, you can get its text content and split it based on
" ":If it’s not already an element, make it one:
Note: this doesn’t take punctuation characters into account – you might want to remove some of them from the string with a simple regex before splitting. Also, if there is only a single word in the text,
lastwill beundefined. If there are no words, 1st will be an empty string,""and last will still beundefined.