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. Advertisements

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. Jason Smith

    Does Python optimize regexes?

    Jason Smith, Jun 29, 2004, in forum: Python
    Replies:
    5
    Views:
    521
  2. Klaus Neuner
    Replies:
    7
    Views:
    809
    Klaus Neuner
    Jul 26, 2004
  3. Ara.T.Howard

    MoinMoin WikiName and python regexes

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

    Timeout and Exponetial Regexes

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

    gsub and regexes on binary files...

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

    Parsing HTML using regexes and arrays.

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

    Switch and capturing regexes

    Joe Gottman, Jun 24, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    128
    topgunroot
    Jun 24, 2005
  8. Peng Yu

    and regexes?

    Peng Yu, Feb 28, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    475
    Peng Yu
    Feb 28, 2012
Loading...