tags:

views:

39

answers:

2

Can anyone help me out with a Regex that will exclude words that are inside: title = "EXCLUDE ANYTHING HERE"

THANKS!

+1  A: 

well, with "regex" you won't exclude nothing. You can use a programing language or editors (vi or sed for example) to match this regex and delete the matched text for you.

what i understood is. You want to delete all UPPERCASE Letters after "title=" right?

with ruby you can do something like that

a = ["title=AAA","title=bbb","title=CCC"]
x = a.collect {|l| l  unless l.split('=')[1] =~ /^[A-Z]+$/ }.compact

at x you will have just the "title=bbb" as you wanted.

VP
A: 

Shorter:

a = ["title=AAA","title=bbb","title=CCC"]
x = a.delete_if { |s| s.match(/=[A-Z]+$/) }

More Rubyish*:

titles = ["title=AAA","title=bbb","title=CCC"]
titles.reject! do |item|
  item.ends_with_caps?
end

class String
  def ends_with_caps?
    self.match /[A-Z]+$/
  end
end

*sarcasm/exaggeration

Mark Thomas