擅长:python、mysql、java
<p>假设您的意思是子部分有3个以上的空格,您可以这样做:</p>
<pre><code>import re
data = '''
*** Section with no sub section
*** Section with sub section ***
*** Sub Section ***
*** Another section
'''
pattern = r'(?:(^ {0,2}\*{3}.*\*{3} *$)|(^ {0,2}\*{3}.*)|(^ *\*{3}.*\*{3} *$))'
regex = re.compile(pattern, re.M)
print regex.findall(data)
</code></pre>
<p>这将为您提供如下分组:</p>
^{pr2}$