Attempting to extract text that is within tags <*word word word*> n times in each line via Python
Question: 
    text =  'the text stuff <*to test*> to find a way to extract all text'\
            'that is <*included in special tags*> less than star and greater'\
            'than star'
    

I've tried using: [Adding up re.finditer
results](http://stackoverflow.com/questions/20404552/adding-up-re-finditer-
results%20using%20yield%20in%20Python%202.7).

I've attempted many regex import re combinations.

I've tried variations of `\w+`.

I can print text with `'<* .... *>'` and replace `'<*'` and `'*>'` with blanks
using `.replace`, but I cannot use a DictReader to extract only the words
within the tags, since the tags appear to be special characters in Python.
Using the DictReader I pull the entire line of text, but not just with words
within the control character tags.

`.split` does work on the text for replace, but not for finding text within a
tag with unusual characters such as `<*...*>`.

I've tried escaping the characters `<`, `*` and `>` as in `\<|*.*?+\*\>` to
find all text within the tags or markers, but this doesn't work.

Python doesn't like these characters being escaped.

I've thought about finding them characters within octal tags for `<`, `*` and
`>` but that may be a distortion of how Python works.

Found good advice from Wes McKinney's and Beazley/Jones' books on Python.

Have tested start and end text, but these special characters don't substitute
well.

Apologize in advance for the complexity of the solutions attempted. Hope I'm
in the ballpark for the approach.

  1. import and register csv
    
        csv.register_dialect('piper', delimiter = '|', quoting=csv.QUOTE_NONE)
    

  2. use a DictReader to read each row 
    
        with open('text') as csvfle:
        for row in csv.DictReader(csvfile, dialect='piper'):
            row["specialtext"] = row["text"].replace("<*", "").replace("*>",           "").decode('windows-1252').encode('utf-8').strip()
            print row['specialtext']
    

all this above works, but any attempt to find the text within the tags,
doesn't.


Answer: Consider using `re.findall()` to extract all matched text into a list and for
any special characters (like asterisk, `*`) escape with backslash:

    
    
    import re
    
    text =  'the text stuff <*to test*> to find a way to extract all text'\
            'that is <*included in special tags*> less than star and greater'\
            'than star'
    
    txtsearch = re.findall('<\*(.*?)\*>', text)
    
    if txtsearch:
        print(txtsearch)
    
    # ['to test', 'included in special tags']
    

