From: Kent Dahl Date: 2001-11-26T21:25:50+09:00 Subject: [ruby-talk:26501] Re: String editing question HarryO wrote: > That was the sort of thing I was getting at if I approached it from > the point of view of the UNacceptable tags. Oh, I read that as "ignore" UNacceptable tags. > If there are many tags in the string, I'd have to do the regexp matching > multiple times. How do I avoid it simply matching the same tags over > and over again (in the case where the regexp matches an acceptable > tag, rather than an unacceptable one)? String.gsub should do the trick. I was thinking something (naive) such as this: str = "


" str.gsub( /<[^>]*>/ ){ |i| puts i; "-"+i.to_s+"-" } Output: "-
- -

- -


- -

-" In the block, i is the match, and whatever value you return from the block, is substituted for the matched regexp. Really naive: legal = ["
","


","

"] str.gsub(/<[^>]*>/){ |i| s = i.to_s; if legal.index(s) then s else s.gsub("<","<").gsub(">",">") end } Output: "


<p align='center'>" HTH -- <[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]> )____(stud.techn.;ind.�k.data)||(softwareDeveloper.at(Trustix))_( /"Opinions expressed are mine and not those of my Employer, "\ ( "the University, my girlfriend, stray cats, banana fruitflies, " ) \"nor the frontal lobe of my left cerebral hemisphere. "/