Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16448

Regex to count words after an underscored word

$
0
0

I want to count an unknown number of words in a string that appear after an underscored word.

testString='21 High Street _Earth Mighty Motor Mechanic'

I can match these words using a non-capture group (?:\s[a-zA-Z]+) But cannot build the regex up to eliminate what comes before the underscored word from the match. See demo

I was looking to use the completed pattern in a Python script as follows:

import repattern = r'(?:\s[a-zA-Z]+)'results = re.findall(pattern, testString)if results:  answer = len(results)

Viewing all articles
Browse latest Browse all 16448

Trending Articles