Note that there are some explanatory texts on larger screens.

plurals
  1. PORegular Expressions in unicode strings
    primarykey
    data
    text
    <p>I have some unicode text that I want to clean up using regular expressions. For example I have cases where u'(2'. This exists because for formatting reasons the closing paren ends up in an adjacent html cell. My initial solution to this problem was to look ahead at the contents of the next cell and using a string function determine if it held the closing paren. I knew this was not a great solution but it worked. Now I want to fix it but I can't seem to make the regular expression work. </p> <pre><code>missingParen=re.compile(r"^\(\d[^\)]$") </code></pre> <p>My understanding of what I think I am doing:<br> ^ at the beginning of the string I want to find<br> ( an open paren, the paren has to be backslashed because it is a special character<br> \d I also want to find a single digit<br> [ I am creating a special character class<br> ^ I don't want to find what follows<br> ) which is a close paren<br> $ at the end of the string </p> <p>And of course the plot thickens I made a silly assumption that because I placed a \d I would not find (33 but I am wrong so I added a {1} to my regular expression and that did not help, it matched (3333, so my problem is more complicated than I thought. I want the string to be only an open paren and a single digit. Is this the more clever approach </p> <pre><code>missingParen=re.compile(r"^\(\d$") </code></pre> <p>And note S Lott _I already tagged it beginner so you can't pick up any cheap points Not that I don't appreciate your insights I keep meaning to read your book, it probably has the answer</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.
 

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