Trying to learn a regular expression
Hello everyone, I am trying to learn regex from java website and I am trying to run this JAVA program, but every time I get No Console output, what should I do? here is the url:
http://java.sun.com/docs/books/tutorial/essential/regex/test_harness.html
I am trying to do this inside eclipse
UPDATE:
Can anyone suggest another better way to find out the regex
source to share
I suggest doing two things:
- Read the first two chapters "Mastering Regular Expressions"
- Buy Regex Buddy. This is a little helper that holds your hand while using and explaining all the markers and grouping options. It allows you to test expressions in the text you are using and also generate code snippets in different languages. I started using it when I needed regular solutions and it quickly led me to a learning curve. Now I don't need this, but I still use it to check some of the tricky group matches that I do to parse the park file. Regex Buddy website
source to share
I had to study RegEx a year ago. I used the Wikipedia page for regex and these two sites were checking the online regex I needed ( Site1 , Site2 ) instead of using regex from UltraEdit ...
It's not as hard as you might think at the beginning
source to share
Yes, what Samir said is true. You can check if your IDE supports console:
if (System.console() == null)
{
System.out.println("No console supported! :-(");
} else
{
System.out.println("Console supported! :-)");
}
You can read the java-doc about System.console();
here
You can see what null
will be returned if the console is missing.
To answer the second question
To print something:
System.out.println("Here your text you want to print");
To read something:
Scanner scanner = new Scanner(System.in);
String oneWord = scanner.next();
String oneLine = scanner.next("\n");
or
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
Hope this helps and you can keep learning about regular expressions!
source to share
Use this site: http://www.fileformat.info/tool/regex.htm
Internally, it uses a package java.util.regex
, so you can worry about learning the regex and still have your knowledge by directly passing the regex in Java when you need it.
source to share