Dear experts, I am trying to build a regular expression to filter out anything between <script ... > and </script> tags where I can specify something using negate class to exclude more than one character in sequence. I tried: originalresponse.gsub(/<script([^>]+)>([^<]+)?<\/script>/,'''') but obviously if the script has the character < before </script> then my regexp breaks. I also tried: originalresponse.gsub(/<script([^>]+)>([^<\/script]+)?<\/script>/,'''') but it doesn''t work Can anyone guide me on how I can specify multiple character negation? I will greatly appreciate it. Is this even possible? How else can I remove everything contained between <script> tags? Thanks Frank --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060219/b1fa7a85/attachment.html
softwareengineer 99
2006-Feb-20 00:15 UTC
[Rails] Multiple Characters Negate Using Regexp - Anyway to specify multiple line regular expression?
Is it possible to specify a multiple line regular expression? Thanks for your assistance. Frank --------------------------------- Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060220/a483c5c6/attachment.html
Jeff Cohen
2006-Feb-20 03:06 UTC
[Rails] Re: Multiple Characters Negate Using Regexp - Anyway to spec
Can you restate your original problem a bit better? Are you wanting to delete everything between the <script> and </script> tags? If so, I think this expression should work (famous last words :-) /(< *script.*?>).*?(<\/ *script *>)/ I tried it like this: irb(main):001:0> "hello <script>goodbye</script> there".gsub(/(< *script.*?>).*?(<\/ *script *>)/,'''') => "hello there" Jeff www.softiesonrails.com -- Posted via http://www.ruby-forum.com/.
I recommend /<script([^>]+)>.*?<\/script>/ Adding the ? after the * makes it un-greedy, so it will match the first following tag, as in the following example. irb(main):001:0> s = "I have a <script foo> tag > inside < me </script> don''cha know </script> :)" => "I have a <script foo> tag > inside < me </script> don''cha know </script> :)" irb(main):002:0> r = /<script([^>]+)>.*?<\/script>/ => /<script([^>]+)>.*?<\/script>/ irb(main):003:0> s.gsub(r,'''') => "I have a don''cha know </script> :)" - Jamie On 2/19/06, softwareengineer 99 <softwareengineer99@yahoo.com> wrote:> Dear experts, > > I am trying to build a regular expression to filter out anything between > <script ... > and </script> tags where I can specify something using negate > class to exclude more than one character in sequence. > > I tried: > > originalresponse.gsub(/<script([^>]+)>([^<]+)?<\/script>/,'''') > > but obviously if the script has the character < before </script> then my > regexp breaks. > > I also tried: > originalresponse.gsub(/<script([^>]+)>([^<\/script]+)?<\/script>/,'''') > > but it doesn''t work > > > Can anyone guide me on how I can specify multiple character negation? > I will greatly appreciate it. > > Is this even possible? How else can I remove everything contained between > <script> tags? > > Thanks > Frank > > > ________________________________ > Yahoo! Mail > Use Photomail to share photos without annoying attachments. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Justin Forder
2006-Feb-24 12:35 UTC
[Rails] Multiple Characters Negate Using Regexp - Anyway to specify multiple line regular expression?
softwareengineer 99 wrote:> Is it possible to specify a multiple line regular expression?yes, just put ''m'' after it, e.g. %r{<textarea[^>]*?id="markup"[^>]*>([^<]*)}m or /<textarea[^>]*?id="markup"[^>]*>([^<]*)/m regards Justin