Python Regex: Using a lookahead
<p>I'm trying to detect text of the following type, in order to remove it from the text:</p>

<pre><code>BOLD:Parshat NoachBOLD:
BOLD:Parshat Lech LechaBOLD:
BOLD:Parshat VayeraBOLD
BOLD:Parshat ShâminiBOLD:
</code></pre>

<p>But only to capture this part:</p>

<pre><code>BOLD:Parshat Noach
BOLD:Parshat Lech Lecha
BOLD:Parshat Vayera
BOLD:Parshat Shâmini
</code></pre>

<p>I thought to use this regex using lookahead:</p>

<pre><code>re.sub(r"BOLD:Parshat .*?(?=(:BOLD))","",comment) #tried lookahead with and without parens
</code></pre>

<p>But it doesn't seem to be detecting them. What might be the problem? The text is followed by a snippet in Hebrew, not sure if that is what is causing the problem.</p>

<p>Please note that these segments are embedded in the middle of different lines, as mentioned followed by a Hebrew snippet.</p>

<p>You don't need look-around just use a capture group and <code>re.MULTILINE</code> flag in order to match a multi line text.</p>

<pre><code>In [8]: s = """BOLD:Parshat NoachBOLD:
   ...: BOLD:Parshat Lech LechaBOLD:
   ...: BOLD:Parshat VayeraBOLD
   ...: BOLD:Parshat ShâminiBOLD:"""

In [9]: re.findall(r'^(BOLD.*)BOLD:?$', s, re.MULTILINE)
Out[9]: 
['BOLD:Parshat Noach',
 'BOLD:Parshat Lech Lecha',
 'BOLD:Parshat Vayera',
 'BOLD:Parshat Shâmini']
</code></pre>

python regex