Can anyone help me out with a Regex that will exclude words that are inside:
title = "EXCLUDE ANYTHING HERE".
            Asked
            
        
        
            Active
            
        
            Viewed 390 times
        
    0
            
            
        - 
                    possible duplicate of http://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string – Youssef Aug 31 '10 at 20:27
2 Answers
1
            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.
        
- 5,122
- 6
- 46
- 71
0
            
            
        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
        
- 37,131
- 11
- 74
- 101
 
    