Gadgets

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

Saturday, 27 February 2016

Regular Expression interview questions

If we represent a group of string objects according to particular patter is called “Regular Expression”. By using Regular Expression we can develop validations and pattern matching etc. Here I have given interview questions on regular expression with examples.
1) What is the Regular Expression?
If we represent a group of string objects according to particular patter is called “Regular Expression”.
import java.util.regex.*;
public class RegularExpres  {
                    public static void main(String[] args)  {
                                         int count=0;
                                         Pattern p=Pattern.compile("a");
                                         Matcher m=p.matcher("abcdabc");
                                         while(m.find()) {
                                                             count++;
                                         System.out.println(m.start()+" "+m.end()+" "+m.group());
                                         }
System.out.println("total : " +count);
                    }
}