I need to make program, that gets optional arguments from command line. In case there shows flag -regex
i need to read folowing regex expression and save it to program as a string.
Something like: java Main -regex *.java
What I have now looks like:
public static void main(String[] args)
...
if (args[i].equals("-regex")) {
String myRegex = args[i+1];
System.out.println(myRegex);
i++;
i++;
}
...
But, as I run program from folder, where are some files as file1.java
and file2.java
, the program prints "file1.java".
What can i do to get my variable with "*.java"?
When I tried to print all the args, with:
for (String arg:args) {
System.out.println(arg);
}
it gives me:
-regex
file1.java
file2.java
Which leads me to conclusion, that I need to read the args differently...