From: Daniel Danopia Date: 2009-10-08T20:00:10+09:00 Subject: Re: Detect any "..." string in a string? On Oct 7, 5:19 pm, Greg Donald wrote: > 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 Donaldhttp://destiney.com/ You could also use a library such as hpricot or nokogiri to search and replace all the tags. And you should have \r\n, not \r, if you are writing HTML.