Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts

Tuesday, October 22, 2013

Searching multiple words in multiple files in eclipse

There are times when we have to search for the occurrences of multiple words in multiple files. In eclipse you can perform this search using File Search with regex expressions.

  • Open Search > File dialog.
  • In the Containing text: field enter (?<!^\s*(//|\*).*)(jack|jim)
  • Select the Regular expression check box and hit the search button.
The above steps shall parse thru all the files selected in the File name patterns section and list all the files with either jack or jim or both.

To understand the expression above, you can refer to http://www.eclipse.org/tptp/home/downloads/installguide/gla_42/ref/rregexp.html

Tuesday, October 21, 2008

Best way to check for all alphabetic, alphanumeric or numeric strings

The best way of checking whether the string is a pure alphabetic, alphanumeric or numeric is to use the String class's matches method by using the regex pattern as a parameter.
  if ("!abc123".matches("[a-zA-Z]*")) {
      System.out.println("Pure alphabetic string");
  } else {
      System.out.println("Not pure alphabets");
  }