From: 7stud -- Date: 2009-10-08T14:30:27+09:00 Subject: Re: Detect any "..." string in a stri Joshua Muheim wrote: > Hi all > > 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. 1)regexes 2)gsub() 3)split() html =< html page Some Email
hello
world
goodbye
Some Email ENDOFHTML new_html = html.gsub(/(.+?)<\/a>/) do |match| p match addy = $1 link = $2 p addy, link pieces = addy.split("?") if pieces.length == 2 puts "there is a query string to parse" name_vals = pieces[1].split("&") p name_vals end puts "the replacement string cobbled together from the pieces above" end puts new_html --output:-- "Some Email" "mailto:some@email.xx" "Some Email" "Some Email" "mailto:some@email.xx?subject=Something&cost=10" "Some Email" there is a query string to parse ["subject=Something", "cost=10"] html page the replacement string cobbled together from the pieces above
hello
world
goodbye
the replacement string cobbled together from the pieces above -- Posted via http://www.ruby-forum.com/.