Identi.ca Identi.ca
  • Login
  • Public

    • Public
    • Groups
    • Featured
    • Popular

Conversation

Notices

  1. Finn Årup Nielsen Finn Årup Nielsen Python

    re.sub('o', '\\', 'ooo') Second argument in !Python re.sub function should be r'ed else an error. Why!?

    Friday, 19-Mar-10 17:46:02 UTC from web at Marburg, Hesse, Germany
    • Philippe Gauthier Philippe Gauthier

      @fnielsen: the string '\\' means really '\', which is not a valid regular expression escape sequence (use r'\\' or '\\\\')

      Friday, 19-Mar-10 17:50:41 UTC
    • Finn Årup Nielsen Finn Årup Nielsen Philippe Gauthier

      @deuxpi Yes, I know. But to me it doesn't make sense that the 2nd argument (the replacement) should be a regular expression...

      Friday, 19-Mar-10 18:06:04 UTC
    • Philippe Gauthier Philippe Gauthier

      @fnielsen: Perhaps you want to use "ooo".replace("o", "\\") then?

      Friday, 19-Mar-10 18:26:08 UTC
    • Marc Rintsch Marc Rintsch

      @fnielsen 2nd argument is not a re but can contain references to groups in the re, e.g.: re.sub('(.)(.)', r'\2\1', 'ab') → 'ba'

      Friday, 19-Mar-10 18:35:58 UTC
    • Radomir Dopieralski Radomir Dopieralski

      @fnielsen r'\' == '\\', r'\\' == '\\\\', and the second argument still needs backslashes escaped (because you can use thngs like \1 in it).

      Friday, 19-Mar-10 20:00:36 UTC
    • pepijndevos pepijndevos

      @fnielsen \\ would result in a single backslash, if you want just a backslash, you'll need four of them.

      Friday, 19-Mar-10 20:05:43 UTC
    • Guy K. Kloss Guy K. Kloss

      @fnielsen '\' is an escape character. e. g. '\n' is a new line, However, r'\n' are two characters, the backslash and the n

      Friday, 19-Mar-10 20:53:53 UTC
    • Finn Årup Nielsen Finn Årup Nielsen Marc Rintsch

      @bj Ahhh. Now I see. With \1 it makes sense to have the second argument handle backslashes.

      Saturday, 20-Mar-10 10:34:55 UTC

Site notice

  • API
  • Status

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

Identi.ca is a microblogging service brought to you by Status.net. It runs the StatusNet microblogging software, version 1.1.0-alpha1, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All Identi.ca content and data are available under the Creative Commons Attribution 3.0 license.

Switch to mobile site layout.

Built in Montreal