Results 1 to 3 of 3
  1. #1
    new_Java is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default How to work with REGEX in Java

    I am having hard time trying to set up a regex in Java for this string "\\abc\de\blah.zip\blah" which is a UNC path in my app.

    I want to look for "\\abc\de" as the regex string in the above mentioned UNC path. However, when I try this method, it returns "false"
    String input = "\\abc\de\blah.zip\blah";
    String regex = "\\*de";
    boolean isMatch = Pattern.matches(regex, input);
    System.out.println(isMatch);

    Please help me.

    Also, if you have any good ref for REGEX online stuff, please let me know. The websites I read, I still could not understand well about these REGEX:(


    Thanks and Regards, KK

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    In regex the backslash has special meaning so you need to escape it, twice. Once for the complier, once for the regex engine.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Also, 'look for' is not the same as matches(...). You probably want to use find()

    db

Similar Threads

  1. Specific syntax? java.util.regex.Pattern$Node
    By lmhelp2 in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 11:32 AM
  2. RegExPlus - Java regex library
    By CodesAway in forum Java Software
    Replies: 5
    Last Post: 02-28-2010, 08:15 PM
  3. Replies: 0
    Last Post: 11-04-2009, 09:09 PM
  4. P~ 0.9 : Java-friendly scripting with powerful regex
    By p7eregex in forum Java Software
    Replies: 0
    Last Post: 12-17-2007, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •