From: Greg Donald Date: 2009-10-08T06:19:47+09:00 Subject: Re: Detect any "..." string in a string? On Wed, Oct 7, 2009 at 3:57 PM, Joshua Muheim wrote: > I have a long, long string of HTML tags. There might be some unprotected > Email links in there like this: > > Some Email > > or > > Some Email > > or... > > I need to detect these email links and substitute them with something > different, like a JavaScript function to obfuscate them: > > obfuscate("some","email.xx","Something","Some Email") > > or something like that. Sadly I have no idea how to find the needed > string parts. I stumbled upon the TMail GEM and guess it could help me a > lot... But I don't get any further now. Here's how I do it in PHP, if you wanna rework it into Ruby: $GLOBALS[ 'EMAIL_LINK_REGEX' ] = "#]*mailto:([^'\" ]*)['\" ]>([^<]*)#i"; $html = preg_replace_callback( $GLOBALS[ 'EMAIL_LINK_REGEX' ], 'fubarEmail', $html ); function fubarEmail( $matches ) { $strNewAddress = replaceEntities( $matches[ 1 ] ); $strText = replaceEntities( $matches[ 2 ] ); $arrEmail = explode( '@', $strNewAddress ); $strTag = "'; return $strTag; } -- Greg Donald http://destiney.com/