I am trying to find certain words in an HTML string. The criteria are any of the followings:
- The word is in the beginning
^
. - The word is in the middle and there is a space before it.
- The word is the in the beginning after a tag.
I am able to get the first two but failing to get the third criteria.
Example string:
Leading a team of 5.
You will be leading a team of 5
<span style="color:#f0f;">Leading a team of 5</span>
The code is ok
He is a good coder
The result should be: [Leading, leading, Leading, He]
My current regex:
/(?:^|\s)(lead[a-z]{0,}|he[\s])/gi
I am using replace to enrich the words, for example:
text.replace(regex, `<b>\$1</b>`);
I cannot figure out how to get the word only.
I know I can remove the (?:^|\s)
part but this will impact small words like he
as it will be matched with the, The ... etc