> Posted this yesterday, but it never made it on the list.
> I'm a little rusty on my regular expressions. Can somebody help me out
> with these two that I'm having problems with.
> The first is
> <cfset st1 = REFindNoCase('Our New Price: <font
> color=".?AA0000">\$([0-9\.]+)<BR></font>',testString,1,"TRUE")>
> <cfset price=Mid(testString,st1.pos[2],st1.len[2])>
> <cfoutput>#price#</cfoutput>
> It's supposed to match
> Our New Price: <font color="#AA0000">$84.00<BR></font>
>
> It works fine, but I think the regex could be better?
>
Try this
<cfset price = REREplaceNoCase(testString,'Our New Price: <font
[^>]*?>\$([\.,0-9]+?)',"\1")>
<cfoutput>#price#</cfoutput>
This will ignore any attributes within the font tag so you don't have to
worry about them changing... It also sets your price with a single <cfset>
rather than 2
> The second one I can't get to match
>
> <cfset st1 = REFindNoCase('<IMG SRC="([.]*)" vspace=0 border=0
> ALT="[A-Za-z ]+" HEIGHT="125" WIDTH="100">',testString,1,"TRUE")>
> <cfset src=Mid(testString,st1.pos[2],st1.len[2])>
> <cfoutput>#src#</cfoutput>
>
> Is supposed to match
>
> <td width="1%"><IMG
> SRC="http://a1204.g.akamai.net/7/1204/1401/02050212011/images.barnesandn
> oble.com/images/5070000/5077366.gif" vspace=0 border=0 ALT="Operating
> Systems" HEIGHT="125" WIDTH="100"></td>
>
> and return the URL.
Depends on your requirements... Do you need the image specifically which has
the ALT attribute of "Operating Systems"? If so, you might try this:
<cfset temp = REREplaceNoCase(testString,'(<img [^>]*?alt="Operating
Systems"[^>]*?>)',"\1")>
<cfset src = REReplaceNoCase(temp,'href="([^"]+?)"',"\1")>
The first regex gets your image tag, then the 2nd regex gets the src
attribute out of that. This should work even if they move the alt tag
around...
hth
Isaac Dealey
Certified Advanced ColdFusion 5 Developer
www.turnkey.to
954-776-0046
______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists