In the spirit of “teaching a man to fish”, should anyone trip over RegEx problems in the future, here are a few resources to help with regular expressions.

 

First, good ol’ Ben Forta came out with a slim little book to help teach RegEx’s, in “Teach Yourself Regular Expressions in 10 Minutes”. It’s available at Amazon at http://www.amazon.com/gp/product/0672325667/.

 

Second, there are various tools to help you build RegEx’s interactively, including

 

http://weitz.de/regex-coach/

http://www.regular-expressions.info/regexbuddy.html

 

and still more listed at places like:

 

http://www.larkware.com/RegexTools.html

http://www.regular-expressions.info/

 

Still another useful tool, which is helpful when one is searching for files having content (or names) matching a given regex, is a free (Windows) tool called Agent Ransack (http://www.agentransack.com). It’s a freeware version of a commercial tool called File Locator Pro. I’ve blogged more details about it before:

 

http://www.tipicalcharlie.com/a_better_file_findsearch_tool_on_windows.htm

 

But even beyond using it for finding files, I sometimes call it up even when I’m not interested in building the RegEx for use in that tool just because I like its regular _expression_ builder.

 

Finally, for those who may wonder why one would care to learn about them, regular expressions can be used in many places, including such file finding tools, and in editors—including Dreamweaver MX, CF Studio, HomeSite+, and CFEclipse), and in CFML itself, in functions like REFind() and REReplace().

 

/Charlie

 


From: [email protected] [mailto:[email protected]] On Behalf Of Taco Fleur
Sent: Thursday, April 13, 2006 5:44 PM
To: [email protected]
Subject: [cfaussie] Re: RegEx brain fart

 

thanks for the help guys, it works pretty smooth now.

On 4/13/06, Tom Kerr <[EMAIL PROTECTED]> wrote:


Hrm, don't have a current CF installation to test this against, but
converting it to sed syntax worked.  It should not perform replacements
on partial tag matches (as per your sometag example below).  I believe
in CF you'd want:

reReplaceNoCase( variables.htmlHighlightedContent,
       "(>[^<]*)(#variables.item#)([^<]*<)",
       "\1<span class='keyword'>\2</span>\3", "all" )

I believe that the example that you said was ok, the one you were
complaining was too slow in a seperate response, will only perform the
replacement on the last matching case of the keyword in the string,
rather than all of them as you seem to require.  This is (as Blair
mentioned in his reply) because of the greedy matching nature of the .*
construct.  Anybody able to confirm these two points?

Most regex implementations have modifiers to produce a lazy .* match,
and I assume CF has the same but no idea what the syntax is.  In general
I find that they complicate your _expression_ more often than they
simplify it anyway.

cheers,

-T

On Thu, Apr 13, 2006 at 04:09:59PM +1000, Taco Fleur wrote:
> this one produces output like
>
> Visual Basic/span>
>
> lets not forget that the word could also be part of a tag, i.e.
>
> <sometag> and the word searched for is "tag"
>
>
> On 4/13/06, Tom Kerr <[EMAIL PROTECTED]> wrote:
> >
> >
> > I believe that should have been ">[^<]*(#variables.item#)[^<]*<".  It
> > might also break if it's possible for variables.item to contain the '<'
> > character.
> >
> > HTH.
> >
> > -T
> >
> > On Thu, Apr 13, 2006 at 02:16:16PM +1000, Taco Fleur wrote:
> > > Almost,
> > > it created the following output, which is a bit of a mess:
> > >
> > > <span style='font-family:Arial;mso-bidi-font-family:
> > >   "Times New Roman"'<span class='keyword'>PHP</span>>
> > >
> > >
> > > On 4/13/06, Blair McKenzie <[EMAIL PROTECTED]> wrote:
> > > >
> > > > If you left the body tags around the content (or div or something)
> > this
> > > > regex should only select keywords that are outside of a tag's <>.
> > > > ">[^<]*(#variables.item#)[^>]*<"
> > > >
> > > > So: Select the keyword if there is no tag opening char between it and
> > the
> > > > last tag close, and there is no tag closing char between it and the
> > next tag
> > > > open.
> > > >
> > > >
> > > >
> > > > On 4/13/06, Taco Fleur <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > >  To split up the html
> > > > >
> > > > > variables.result = reFindNoCase( "<body[^>]+>(.+)</body>",
> > > > > variables.htmlContent, 1, true );
> > > > > variables.htmlContentHeader = left( variables.htmlContent,
> > result.pos[ 2
> > > > > ] );
> > > > > variables.htmlContentBody = mid( variables.htmlContent, result.pos[
> > 2 ],
> > > > > result.len[ 2 ] );
> > > > > variables.htmlContentFooter = right( variables.htmlContent, ( len(
> > > > > variables.htmlContent ) +1 ) - ( result.pos[ 2 ] + result.len[ 2 ]
> > ));
> > > > >
> > > > > To highlight the keyword
> > > > >
> > > > > <cfset variables.htmlHighlightedContent = reReplaceNoCase(
> > > > > variables.htmlHighlightedContent, "(#variables.item#)", "<span
> > > > > class='keyword'>\1</span>", "all" ) />
> > > > >
> > > > >
> > > > >  On 4/13/06, Blair McKenzie <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > What are you using at the moment?
> > > > > >
> > > > > >
> > > > > > On 4/13/06, Taco Fleur <[EMAIL PROTECTED] > wrote:
> > > > > > >
> > > > > > >  I'm drawing a blank on coming up with a regex for the
> > following;
> > > > > > >
> > > > > > > I have some HTML that I read in a variable, then I highlight the
> > > > > > > keywords with a regex, which is fine, but some keywords might be
> > contained
> > > > > > > within a tag, for example <html><strong> etc, I don't want to
> > highlight
> > > > > > > those, what would the regex need to look like, anyone any idea
> > on this one?
> > > > > > >
> > > > > > > thanks.
> > > > > > >
> > > > > > > --
> > > > > > > Taco Fleur - http://www.pacificfox.com.au
> > > > > > > Web Design, Web development, Graphic Design and Complete
> > Internet
> > > > > > > Solutions
> > > > > > > an industry leader with commercial IT experience since 1994 ?
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > an industry leader with commercial IT experience since 1994 ?
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > > >
> > > >
> > >
> > >
> > > --
> > > Taco Fleur - http://www.pacificfox.com.au
> > > Web Design, Web development, Graphic Design and Complete Internet
> > Solutions
> > > an industry leader with commercial IT experience since 1994 ?
> > >
> > >
> > >
> >
> > >
> >
>
>
> --
> Taco Fleur - http://www.pacificfox.com.au
> Web Design, Web development, Graphic Design and Complete Internet Solutions
> an industry leader with commercial IT experience since 1994 ?
>
>
>


--
Taco Fleur - http://www.pacificfox.com.au
Web Design, Web development, Graphic Design and Complete Internet Solutions
an industry leader with commercial IT experience since 1994 …


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cfaussie" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cfaussie
-~----------~----~----~----~------~----~------~--~---

Reply via email to