Setting locale for java.util.regex at runtime

Discussion in 'Java' started by Alex Polite, Jun 5, 2004.

  1. Alex Polite

    Alex Polite Guest

    "\w" doesn't match wordchars outside of [A-Za-z].

    I suppose that this is in some way controlled by locale.

    Is there any way to make this localesetting at runtime?

    alex

    --
    Alex Polite
    http://polite.se
     
    Alex Polite, Jun 5, 2004
    #1
    1. Advertising

  2. Alex Polite

    Alan Moore Guest

    On 5 Jun 2004 20:52:22 GMT, Alex Polite <> wrote:

    >"\w" doesn't match wordchars outside of [A-Za-z].
    >
    >I suppose that this is in some way controlled by locale.
    >
    >Is there any way to make this localesetting at runtime?
    >
    >alex


    The java.util.regex package is not locale-senistive at all. The
    character-class shorthands (\w, \d, \s) and POSIX character classes
    (\p{Alpha}, \p{Digit}, etc.) only ever match ASCII characters. If you
    want to match non-ASCII characters, you have to use Unicode blocks
    like \p{InGreek}, or categories like \p{IsLetter} (which can be
    shortened to \pL).

    Oddly enough, the word-boundary construct, \b, works with *all*
    Unicode letters and digits, not just the ASCII ones. That makes sense
    when I think about how frustrating it would be if it didn't, but it
    makes it seem that much stranger that \w, \d and \s are limited to the
    ASCII range.
     
    Alan Moore, Jun 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Torsten Bronger

    Setting locale at runtime

    Torsten Bronger, Apr 11, 2005, in forum: C Programming
    Replies:
    3
    Views:
    432
    Peter Nilsson
    Apr 12, 2005
  2. Replies:
    2
    Views:
    498
    Jerry Coffin
    Jul 23, 2006
  3. napo
    Replies:
    13
    Views:
    7,724
    chaitanyat2001
    Sep 23, 2008
  4. Sibylle Koczian
    Replies:
    2
    Views:
    1,154
    Sibylle Koczian
    Nov 20, 2010
  5. Vlastimil Brom
    Replies:
    0
    Views:
    987
    Vlastimil Brom
    Dec 9, 2010
Loading...

Share This Page