File.separatorChar and regexes.

Discussion in 'Java' started by Roedy Green, Aug 22, 2003.

  1. Roedy Green

    Roedy Green Guest

    You will need some code like this if you want to include separator
    character in your regexes, since \ has to be quoted in regexes.
    You might not catch this problem if you are developing on a platform
    where / is the default.

    private static final
    String sepStr = File .separatorChar == '\\' ? "\\\\" : String.valueOf
    ( File.separatorChar );

    private static final
    Pattern slashSplitter = Pattern .compile( sepStr );
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 22, 2003
    #1
    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. Ara.T.Howard

    MoinMoin WikiName and python regexes

    Ara.T.Howard, Jun 8, 2005, in forum: Python
    Replies:
    6
    Views:
    692
    Bengt Richter
    Jun 26, 2005
  2. eden li

    Timeout and Exponetial Regexes

    eden li, Sep 28, 2006, in forum: Ruby
    Replies:
    4
    Views:
    173
    Rick DeNatale
    Oct 5, 2006
  3. Kyle Schmitt

    gsub and regexes on binary files...

    Kyle Schmitt, Jan 17, 2008, in forum: Ruby
    Replies:
    2
    Views:
    93
    Kyle Schmitt
    Jan 17, 2008
  4. soldier.coder

    Parsing HTML using regexes and arrays.

    soldier.coder, Nov 7, 2008, in forum: Ruby
    Replies:
    1
    Views:
    94
    Michael Libby
    Nov 7, 2008
  5. Joe Gottman

    Switch and capturing regexes

    Joe Gottman, Jun 24, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    70
    topgunroot
    Jun 24, 2005
Loading...

Share This Page