On Fri, Jan 8, 2010 at 12:28 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> Dave McCormick wrote: > >> >> >> On Wed, Jan 6, 2010 at 9:18 AM, John Posner <jjpos...@optimum.net<mailto: >> jjpos...@optimum.net>> wrote: >> >> On Tue, 05 Jan 2010 16:54:44 -0500, Dave McCormick >> <mackrac...@gmail.com <mailto:mackrac...@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 >> >> -John >> >> -- http://mail.python.org/mailman/listinfo/python-list >> >> I need another hint... >> >> Been doing some reading and playing and it looks like >> r'\bxxx\b' >> is what I need. But I can not figure out how to pass a variable between >> \b___\b >> 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 > this: > > r'\b(?:' + greenList_regexp + ')\b' > > > Thanks but that did not work either. Maybe I have something else wrong too? complete_text = Tbox.get("1.0", END) greenList = "green grass".split() greenList_regexp = "|".join(greenList) for matchobj in re.finditer(r'\b(?:' + greenList_regexp + ')\b', complete_text): start,end = matchobj.span() Tbox.tag_add("green", "1.0 + %d chars" % start,"1.0 + %d chars" % end) Tbox.tag_config("green", foreground="green") The words "green" and "grass" do not turn green. Dave
-- http://mail.python.org/mailman/listinfo/python-list