Question: I am currently learning python. I do not want to use Biopython, or really any imported modules, other than maybe regex so I can understand what the code is doing.

From a genetic sequence alignment, I would like to find the location of the start and end positions of gaps/indels "-" that are next to each other within my sequences, the number of gap regions, and calculate the length of gap regions. For example:

```
>Seq1
ATC----GCTGTA--A-----T

```

I would like an output that may look something like this:

```
Number of gaps = 3

Index Position of Gap region 1 = 3 to 6
Length of Gap region 1 = 4

Index Position of Gap region 2 = 13 to 14
Length of Gap region 2 = 2

Index Position of Gap region 3 = 16 to 20
Length of Gap region 3 = 5

```

I have tried to figure this out on larger sequence alignments but I have not been able to even remotely figure out how to do this.

Answer: 
What you want is to use regular expression to find a gap (one or more dashes, which translate to '-+', the plus sign means *one or more*):

```
import re

seq = 'ATC----GCTGTA--A-----T'
matches = list(re.finditer('-+', seq))

print 'Number of gaps =', len(matches)
print

for region_number, match in enumerate(matches, 1):
    print 'Index Position of Gap region {} = {} to {}'.format(
            region_number,
            match.start(),
            match.end() - 1)
    print 'Length of Gap region {} = {}'.format(
            region_number,
            match.end() - match.start())
    print

```

Notes
=====

* `matches` is a list of match objects
* In order to get the region number, I used the function `enumerate`. You can look it up to see how it works.
* The match object has many methods, but we are interested in `.start()` which returns the start index and `.end()` which return the end index. Note that the *end index* here is one more that what you want, thus I subtracted 1 from it.
Here is my suggestion of code, quite straight-forward, short and easy to understand, without any other imported package other than `re`: 

```
import re

def findGaps(aSeq):
    # Get and print the list of gaps present into the sequence
    gaps = re.findall('[-]+', aSeq)
    print('Number of gaps = {0} \n'.format(len(gaps)))
    # Get and print start index, end index and length for each gap
    for i,gap in enumerate(gaps,1):
        startIndex = aSeq.index(gap)
        endIndex = startIndex + len(gap) - 1
        print('Index Position of Gap region {0} = {1} to {2}'.format(i, startIndex, endIndex))
        print('Length of Gap region {0} = {1} \n'.format(i, len(gap)))
        aSeq = aSeq.replace(gap,'*' * len(gap), 1)

findGaps("ATC----GCTGTA--A-----T")

```