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

+2


source to share


7 replies


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
+1


source


Are you running the application in an IDE like Eclipse or IntelliJ IDEA? Try using the command line instead. Some IDEs will make calls System.console()

.



+2


source


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

+1


source


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!

0


source


I suggest you learn regex with Perl. It is much better integrated than Java

0


source


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.

0


source


You can try different types of regex with eclipses find / replace (or with some ide text editor that supports regex).

Python or Ruby interactive shells are good places to test regex (and the regex syntax is much nicer than Java).

And, of course, there is the internet.

0


source







All Articles