Dynamic text color
python at mrabarnett.plus.com
Fri Jan 8 20:28:57 CET 2010
Dave McCormick wrote:
> On Wed, Jan 6, 2010 at 9:18 AM, John Posner <jjposner at optimum.net
> <mailto:jjposner at optimum.net>> wrote:
> On Tue, 05 Jan 2010 16:54:44 -0500, Dave McCormick
> <mackrackit at gmail.com <mailto:mackrackit at gmail.com>> wrote:
> But it is not what I am wanting. I first thought to make it look
> for a space but that would not work when a single character like
> "#" is to be colored if there is a "string" of them. Or if all
> of the characters between quotes are to be colored.
> Regular expressions are good at handling searches like:
> * all the characters between quotes
> * the two-character string "do", but only if it's a complete word
> I need another hint...
> Been doing some reading and playing and it looks like
> is what I need. But I can not figure out how to pass a variable between
> If the word in question is between the "\b \b" and in the list then it
> works like I want it to.
> The below does not work.
> greenList_regexp = "|".join(greenList)
> for matchobj in re.finditer(r'\bgreenList_regexp\b', complete_text):
> start,end = matchobj.span()
The regex r'\bgreenList_regexp\b' will match the string
'greenList_regexp' if it's a whole word.
What you mean is "any of these words, provided that they're whole
words". You'll need to group the alternatives within "(?:...)", like
r'\b(?:' + greenList_regexp + ')\b'
More information about the Python-list