Give this a go: <cfset Result = InputText.replaceAll ( '~\{(?:(?!</a>).)+(?<!\}~)(?=</a></li>)' , '$0}~' ) />
It uses the java replaceAll regex function so that it can do the negative lookbehind to ensure existing correct items are not changed, meaning it can be run multiple times. Accepts any character (except newline) until it finds a closing A tag. If newlines are required, that's just a one character change: '~\{(?s:(?!</a>).)+(?<!\}~)(?=</a></li>)' (Which adds the 's' flag into what was a non-capturing group, meaning '.' also matches newlines.) If there's the possibly of a '~{' appearing outside this context, it may need extra limits applied to work correctly. Assuming there should not be any tags inside the ~{...}~ part, I would change the '.' for a '[^<>]' which makes it a bit 'safer': '~\{(?:(?!</a>)[^<>])+(?<!\}~)(?=</a></li>)' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:345282 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm