get start and end of regex match in dataframe
What about including a method to get the start and stop after a regex search of items in a DataFrame . Perhaps using .str.extract?

Returning the start as a new column would perhaps be as follows:

```
df['start'] = df['string'].str.extract(pattern, output = 'start')
```

an alternative suggestion from jkitchen on StackOverflow was to use start_index = True, or end_index = True

```
df['start'] = df['string'].str.extract(pattern, start_index = True)
```

For multiple parameters (e.g. start and end) as outputs, there needs to be a way to avoid running the search twice. One solution would be to give the output as a tuple:

```
df['regex_output_tuple'] = df['string'].str.extract(pattern, output = ('start','end'))
```

I don't use regex very often, so I don't know if there are other parameters that people want after a regex search. If there really is just the text in the groups, the start and the end, perhaps there's a way to put the output directly into new columns?

```
df['groups'], df['start'], df['end']  = df['string'].str.extract(pattern, output = ('groups','start','end'))
```

I think it makes sense that non-matches return a NaN, just as in the regular extract function. This would mix integer and float datatypes in the  df['start'] column, but I guess we all know about that situation :)

I'm not an experienced programmer, so sorry if I misunderstood some basic concepts.

Please see the question in StackOverflow for example code and comments:
http://stackoverflow.com/questions/26658213/how-can-i-find-the-start-and-end-of-a-regex-match-using-a-python-pandas-datafram

A block of example data and code is below, as requested by jreback.

```
import pandas as pd
import re
#some example query sequences, markup strings, hit sequences.
q1,q2,q3 = 'MPIMGSSVYITVELAIAVLAILG','MPIMGSSVYITVELAIAVLAILG','MPI-MGSSVYITVELAIAVLAIL'
m1,m2,m3 = '|| ||  ||||||||||||||||','||   | ||| :|| || |:: |','||:    ::|: :||||| |:: '
h1,h2,h3 = 'MPTMGFWVYITVELAIAVLAILG','MP-NSSLVYIGLELVIACLSVAG','MPLETQDALYVALELAIAALSVA' 
#create a pandas dataframe to hold the aligned sequences
df = pd.DataFrame({'query':[q1,q2,q3],'markup':[m1,m2,m3],'hit':[h1,h2,h3]})

#create a regex search string to find the appropriate subset in the query sequence, 
desired_region_from_query = 'PIMGSS'
regex_desired_region_from_query = '(P-*I-*M-*G-*S-*S-*)'

#Pandas has a nice extract function to slice out the matched sequence from the query:
df['extracted'] = df['query'].str.extract(regex_desired_region_from_query)

#However I need the start and end of the match in order to extract the equivalent regions 
#from the markup and hit columns. For a single string, this is done as follows:
match = re.search(regex_desired_region_from_query, df.loc[2,'query'])
sliced_hit = df.loc[2,'hit'][match.start():match.end()]
print('sliced_hit, non-vectorized example: ', sliced_hit)

#HERE the new syntax is necessary
#e.g. df['start'], df['end']  = df['string'].str.extract(pattern, output = ('start','end'))

#My current workaround in pandas is as follows.
#define function to obtain regex output (start, stop, etc) as a tuple
def get_regex_output(x):
    m = re.search(regex_desired_region_from_query, x)
    return (m.start(), m.end())
#apply function
df['regex_output_tuple'] = df['query'].apply(get_regex_output)
#convert the tuple into two separate columns
columns_from_regex_output = ['start','end']      
for n, col in enumerate(columns_from_regex_output):
    df[col] = df['regex_output_tuple'].apply(lambda x: x[n])
#delete the unnecessary column
df = df.drop('regex_output_tuple', axis=1)
```
