I'm writing a jQuery plugin to highlight C++ code on my webpages. I'm not really too good with RegEx, so I can't figure out how to highlight keywords (like 'if', 'case', 'void', etc.) without highlighting parts of words (Like the 'int' in 'Paint'). I changed it a bit, but some things still don't get highlighted. This is what my RegEx looks like:
str = str.replace(new RegExp("([' ' || \t ||,|| \"\"])(" + ParserKeywordsArr[i] + ")", 'g'), "$1<span style='color:" + ParserColorsArr[i] + ";'>" + ParserKeywordsArr[i] + "</span>");
This goes through every keyword I want highlighted, which is stored in an array, and theres another array with the colors (Ex. ParserKeywordsArr[0] is void, ParserColorsArr[0] is blue, so it would highlight in blue). However, when I put in something like this:
void CCodeEditorCtrl::OnPaint(WPARAM wParam, LPARAM lParam)
{
return;
}
Return gets highlighted, but void doesn't. I don't know how to tell RegEx "If its the first word on the line, and it matches a keyword, highlight it"