Regular Expressions Interview Questions And Answers

Regular Expressions Interview questions and answers for all language like PHP, Java, .net etc developer with lot of examples of complex search pattern and rewrite rules in Apache and .htaccess

Top Regular Expressions interview questions and answers

Questions : 1 What is the mean of Regular Expressions ? What the use of Regular Expressions ?
Answers : 1 Regular Expressions means we can say a pattern that one is an expression that
specifies a set of strings. And there are lot of great use of these expressions like
  • In complex search
  • In validation like email validation or URl validation etc
  • in writing of rewrite rules in apache or .htaccess file
  • in file search in linux
  • in pattern matches
Questions : 2 What the mean of different symbols like ^, $, * , + , ?, ., {},[]
in Regular Expressions
Answers : 2 These symbols ^, $, * , + , ?, ., {},[] are very usefull like
  • "^PCDS": Symbols ^ use to matches any string that starts with "PCDS"
    this can match "PCDS is an Infotech";
  • "pcds$": Matches a string that ends in the substring "pcds"
    like "This is pcds";
  • "^pcds$": Matches a string that starts and ends with "pcds"
    that could only be "pcds" itself
  • "ab*": matches a string that has an a followed by zero or more b's ("a", "ab", "abbb", etc.);
  • "ab+": same as *, but there's at least one b ("ab", "abbb", etc.);
  • "ab?": there might be a b or not;
  • "ab.": . matches any character like abd, abh, abt etc;
  • "ab{2}": matches a string that has an a followed
    by exactly two b's ("abb");
  • "ab{2,}": there are at least two b's ("abb", "abbbb", etc.);
  • "ab{3,5}": from three to five b's ("abbb", "abbbb", or "abbbbb").
  • "[a-z]": matches any char from a to z.
Questions : 3 How we list which characters we DON'T want ?How to use backslash character
Answer : 3 We can list which characters we DON'T want so just use a '^' as the first symbol in a bracket expression
(i.e., "%[^a-zA-Z]%" matches a string with a character that is not a letter between two percent signs).
"^[a-zA-Z]": a string that starts with a letter;
"[0-9]%": a string that has a single digit before a percent sign;
",[a-zA-Z0-9]$": a string that ends in a comma followed by an alphanumeric character.

In order to be taken literally, you must escape the characters "^.[$()|*+?{\" with a backslash ('\'), as they have special meaning. On top of that, you must escape the backslash character itself in PHP3 strings, so, for instance, the regular expression "(\$|)[0-9]+" would have the function call: ereg("(\\$|)[0-9]+", $str)

Questions : 4 How you can validate email id use REG expression
Answer : 4
By using below reg expression we can validate email id


"^[_a-z0-9-]+": start with any underscore or alphanumeric one or more then one alfanumaric word
"(\.[_a-z0-9-]+)*@":any dot(.) or alphanumeric zero times or more the zero and a @ sign
"[a-z0-9-]+":one or more alphanumeric
"(\.[a-z0-9-]+)*": zero or more dot alphanumeric or -(mins sign)
"(\.[a-z]{2,5})$": End with two to 5 character may use dot (.) in that

Next Page 1 | Next Page 2 | Next Page 3

Ask your interview questions on Regular expression

Write Your comment or Questions if you want the answers on Regular expression from Regular expression Experts
Name* :
Email Id* :
Mob no* :
Comment* :


--------- Tutorials ---