Wednesday, 7 October 2015

Regular Expression Interview Questions and Answers


Regular Expression Interview Questions and Answers


Question: What is the mean of Regular Expressions?
Regular Expressions is a pattern which is used to search string like "Search name start with a" OR "Search name end with z".


Question: What is use of Regular Expressions?
It is used to Search Simple String OR Complex String.
For Example:
Search all name start with a.
Search all names end with a


Question:What the mean of different symbols like ^ $ in Regular Expression?
^a Search all string which start with "a".
a$ Search all string which end with "a".
[a-z0-9]{2,5} there should be 2-5 string which can be a-z and 0-9 characters.
[a-z]{2,5} there should be 2-5 string which are a-z characters.
[0-9]{2,5} there should be 2-5 string which are 0-9 characters.


Question: What is Regular Expression to validate Email?
^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$


Question: Write a Regular expression to match line that doesn't contain a word?
To find a word "FINDME" in String.
^((?!FINDME).)*$


Question: How do I remove all non alphanumeric characters from a string?
Suppose you want to remove all character except a-z, 0-9 and "space".
[^a-zA-Z0-9\s] 


Question: Simple regular expression for a decimal with a precision of 2
\d+(\.\d{1,2})?