Q:

Extracting string with set no. of hyphen

If I have an example string as follows: 
LEARNING-LEARNING-LEARNING-LEARNING-LEARNING-COMPANY_ORG_CHART-LEARNING-LEARNING-LEARNING-END

I want to extract only the first n no. of steps where n is defined by the no. of hyphens in between. 
So if n=5, 

I want only the first 5 steps. 
Output: 
LEARNING-LEARNING-LEARNING-LEARNING-LEARNING

I tried this: 
s1=re.search(r'([A-za-z_].*-{0,5}[A-za-z_].*?)',s)
print(s1.group())

But it is giving whole string as output. 
LEARNING-LEARNING-LEARNING-LEARNING-LEARNING-COMPANY_ORG_CHART-LEARNING-LEARNING-LEARNING-END
In [ ]:

A:

If this is the actual format, then regex may be overkill for the sample provided. One other option is just using string methods and indexing:
x='LEARNING-LEARNING-LEARNING-LEARNING-LEARNING-COMPANY_ORG_CHART-LEARNING-LEARNING-LEARNING-END'

print('-'.join(x.split('-')[:5]))

'LEARNING-LEARNING-LEARNING-LEARNING-LEARNING'

