Wednesday, July 9, 2008

Regular Expression

This is a simple java application for using regular expressions in Java.

import java.util.regex.*;

public class Regex {

public static void main(String[] args) throws Exception {

Pattern p = Pattern.compile("[,\\s]+");
String[] result = p.split("one,two, three four , five");
for (int i=0; i System.out.println(result[i]);



String textSubject = "aasasa2323";
Pattern brackets = Pattern.compile(".*\\{[h][e][l][l][o]\\}.*");
Matcher fit = brackets.matcher(textSubject);
if (fit.find()) {
System.out.println ("Found");
} else {
System.out.println ("Not found");
}

}

}

No comments: