Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The dash character in your text is <a href="http://www.fileformat.info/info/unicode/char/2013/index.htm" rel="nofollow"><code>EN DASH U+2013</code></a>, that's why <code>([^-])</code> matches the <code>EN DASH</code> and a replacement occurs.</p> <p>You need to add the character into your character class, and shift the <code>\s*</code> to the first capturing group, and add <code>\s</code> to the negated character class to make it works as you want:</p> <pre><code>re.sub(r'([^\s–-]\s*)(&lt;br)',r'\1\n\2', astring) </code></pre> <p>Note that while the code above works, it is not maintainable - since it is very hard to notice the <code>EN DASH</code> in the character class.</p> <p>From <a href="http://docs.python.org/3.3/library/re.html" rel="nofollow">Python 3.3</a> and above, <code>\u</code> or <code>\U</code> Unicode escape sequence has been added. You can specify your regex as such:</p> <pre><code>re.sub(r'([^\s\u2013-]\s*)(&lt;br)',r'\1\n\2', astring) </code></pre> <p>It is arguably less clear what <code>\u2013</code> is, but at least, reader of the code won't get tripped.</p> <p>For Python 3.2 and below, you can use the normal literal string instead of raw literal string syntax for the regex to achieve the same effect.</p> <pre><code>re.sub('([^\\s\u2013-]\\s*)(&lt;br)',r'\1\n\2', astring) </code></pre> <p>Technically, due to Python's way of parsing literal string (preserve the <code>\</code> if it does not form a valid escape sequence), <code>'([^\s\u2013-]\s*)(&lt;br)'</code> also works (compare <code>\\s</code> and <code>\s</code>), but I double up the escape just to be safe.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload