• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular expression  RSS feed

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.regex.*;
public class Test {
public static void main(String[] args) {
final Pattern absPattern =
Pattern.compile("[a-zA-Z]\\:\\\\(.*)");
Matcher matcher = absPattern.matcher(args[0]);
System.out.println(matcher.matches());
}
when I call this from command line
java Test C:\ds
I get false why?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alok,
It would be much easier to read your code if you put it into UBB
The first case I quoted the string so that the OS did not try any translations.
The second case is like yours.
The third case I escaped the backslash so the OS passed a single backslash to the JVM.
Not much Java can do if the operating system modifies your command line.
Regards, Andrew
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!