regular expression unicode character class trouble

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Diez B. Roggisch

    #1

    regular expression unicode character class trouble

    Hi,

    I need in a unicode-environment the character-class

    set("\w") - set("[0-9]")

    or aplha w/o num. Any ideas how to create that? And what performance
    implications do I have to fear? I mean I guess that the characterclasse s
    aren't implementet as sets, but as comparison-function that compares a
    value with certain well-defined ranges.

    Regards,

    Diez
  • Steven Bethard

    #2
    Re: regular expression unicode character class trouble

    Diez B. Roggisch wrote:[color=blue]
    > Hi,
    >
    > I need in a unicode-environment the character-class
    >
    > set("\w") - set("[0-9]")
    >
    > or aplha w/o num. Any ideas how to create that?[/color]

    I'd use something like r"[^_\d\W]", that is, all things that are neither
    underscores, digits or non-alphas. In action:

    py> re.findall(r'[^_\d\W]+', '42badger100x__ xxA1BC')
    ['badger', 'x', 'xxA', 'BC']

    HTH,

    STeVe

    Comment

    • Diez B. Roggisch

      #3
      Re: regular expression unicode character class trouble

      Steven Bethard wrote:[color=blue]
      > I'd use something like r"[^_\d\W]", that is, all things that are neither
      > underscores, digits or non-alphas. In action:
      >
      > py> re.findall(r'[^_\d\W]+', '42badger100x__ xxA1BC')
      > ['badger', 'x', 'xxA', 'BC']
      >
      > HTH,[/color]

      Seems so, great!

      Diez

      Comment

      Working...