Re: Reuse regular sub-expression in larger expression
Yeah, you can do that. Here's a simple example of it in action (using the backreference to match quotes). It also uses a non-greedy modifier in there to avoid doing an incorrect match on the apostrophe within the double quotes. cheers, barneyb cfoutput cfset baseString = some 'text' with quotes an' some apostrophes in it / h2Quoted Strings within #baseString#/h2 ul cfset start = 1 / cfloop condition=true cfset result = REFind((['])(.*?)\1, baseString, start, true) / cfif result.pos[1] LT 1 cfbreak / /cfif cfset string = mid(baseString, result.pos[3], result.len[3]) / cfset quote = mid(baseString, result.pos[2], result.len[2]) / cfset start = result.pos[1] + result.len[1] / li#string# (quoted with #quote#)/li /cfloop /ul /cfoutput On Nov 8, 2007 2:16 PM, Andy Matthews [EMAIL PROTECTED] wrote: Adam Howitt wrote a blog post asking for improvements to a regex that he wrote: http://tinyurl.com/yvzxjk This is what I came up with: \(-?[\w,.]+/-?[\w,.]+\) But I'm wondering if it's possible to reuse the first portion of the expression, rather than writing the same exact thing twice in one string. So rather than this: \(-?[\w,.]+/-?[\w,.]+\) I could have this: \((-?[\w,.]+)/\1\) or something like that. I could swear that I've seen someone do this before. Andy Matthews -- Barney Boisvert [EMAIL PROTECTED] http://www.barneyb.com/ Got Gmail? I have 100 invites. ~| Get involved in the latest ColdFusion discussions, product development sharing, and articles on the Adobe Labs wiki. http://labs/adobe.com/wiki/index.php/ColdFusion_8 Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293009 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Reuse regular sub-expression in larger expression
There may be a way, but I've not run across it yet. If you are really intent on it, you could simplify it using CF itself. cfset thing = -?[\w,.]+ and then use \(#thing#/#thing#\) For something this trivial, it seems a bit pointless, but for large and complicated subexpressions, it might be worthwhile. I know that I often do something like this for linebreaks so that I can easily change which linebreak I'm using, and not have to make sure I get every instance. :-) What can I say -- I'm lazy. --Ben Doom Andy Matthews wrote: Adam Howitt wrote a blog post asking for improvements to a regex that he wrote: http://tinyurl.com/yvzxjk This is what I came up with: \(-?[\w,.]+/-?[\w,.]+\) But I'm wondering if it's possible to reuse the first portion of the expression, rather than writing the same exact thing twice in one string. So rather than this: \(-?[\w,.]+/-?[\w,.]+\) I could have this: \((-?[\w,.]+)/\1\) or something like that. I could swear that I've seen someone do this before. Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com http://www.dealerskins.com/ ~| Enterprise web applications, build robust, secure scalable apps today - Try it now ColdFusion Today ColdFusion 8 beta - Build next generation apps Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293039 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Reuse regular sub-expression in larger expression
IIRC, this only works if you want the same string for both matches. I don't think that is what Andy wanted. --Ben Doom Barney Boisvert wrote: Yeah, you can do that. Here's a simple example of it in action (using the backreference to match quotes). It also uses a non-greedy modifier in there to avoid doing an incorrect match on the apostrophe within the double quotes. cheers, barneyb cfoutput cfset baseString = some 'text' with quotes an' some apostrophes in it / h2Quoted Strings within #baseString#/h2 ul cfset start = 1 / cfloop condition=true cfset result = REFind((['])(.*?)\1, baseString, start, true) / cfif result.pos[1] LT 1 cfbreak / /cfif cfset string = mid(baseString, result.pos[3], result.len[3]) / cfset quote = mid(baseString, result.pos[2], result.len[2]) / cfset start = result.pos[1] + result.len[1] / li#string# (quoted with #quote#)/li /cfloop /ul /cfoutput On Nov 8, 2007 2:16 PM, Andy Matthews [EMAIL PROTECTED] wrote: Adam Howitt wrote a blog post asking for improvements to a regex that he wrote: http://tinyurl.com/yvzxjk This is what I came up with: \(-?[\w,.]+/-?[\w,.]+\) But I'm wondering if it's possible to reuse the first portion of the expression, rather than writing the same exact thing twice in one string. So rather than this: \(-?[\w,.]+/-?[\w,.]+\) I could have this: \((-?[\w,.]+)/\1\) or something like that. I could swear that I've seen someone do this before. Andy Matthews ~| Download the latest ColdFusion 8 utilities including Report Builder, plug-ins for Eclipse and Dreamweaver updates. http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293037 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Reuse regular sub-expression in larger expression
Adam Howitt wrote a blog post asking for improvements to a regex that he wrote: http://tinyurl.com/yvzxjk This is what I came up with: \(-?[\w,.]+/-?[\w,.]+\) But I'm wondering if it's possible to reuse the first portion of the expression, rather than writing the same exact thing twice in one string. So rather than this: \(-?[\w,.]+/-?[\w,.]+\) I could have this: \((-?[\w,.]+)/\1\) or something like that. I could swear that I've seen someone do this before. Andy Matthews Senior ColdFusion Developer Office: 877.707.5467 x747 Direct: 615.627.9747 Fax: 615.467.6249 [EMAIL PROTECTED] www.dealerskins.com http://www.dealerskins.com/ ~| ColdFusion is delivering applications solutions at at top companies around the world in government. Find out how and where now http://www.adobe.com/cfusion/showcase/index.cfm?event=finderproductID=1522loc=en_us Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292989 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4