Regular Expressions Interview Questions and Answers
Question - 21 : - What is meta character represent the space in Regular expressions?
Answer - 21 : -
\s - is used represent the space
\s* - represent more than one whitespace.
Shiva\s*Gummadidala
Shiva Gummadidala
Question - 22 : - What is escape sequence character in Regex?
Answer - 22 : -
'\' character represent escape sequence.
Want to match any character which is having special meaning then we use escape sequence character.
a\^b will match a^b
Question - 23 : - What is regular expression flags ?
Answer - 23 : -
Ragular expression flags sometimes called as modifiers , they are effect the way of pattren matching.
Different kinds of flags available
/g,/i etc.
Question - 24 : - What is meta character in Regular expressions?
Answer - 24 : -
Meta characters used to form syntax of regular expressions.
Ex: ^, .,& etc..
Question - 25 : - Can we give regular expression range in descending order like [20-10] ?
Answer - 25 : -
No , we shouldn't give , if you give will out of range expression error.
Question - 26 : - What is CapturingGroup Regular expressions?
Answer - 26 : -
-if you feel portion of the regex using later part of the regex then we use capturing groups.
-its represent with meta characters inside parenthesis and its repetitions represented with \1 , \2 etc..
- its also called as Backreferencing
(abcd)(efgh) \1\2 will match abcdefghabcdefgh
Question - 27 : - What is NonCapturingGroup Regular expressions?
Answer - 27 : -
if you want to make capturing group as non NonCapturingGroup use ?:.
(?:abcd) is NonCapturingGroup - can not use this group later.
Question - 28 : - What is the difference between ([PQR]+) and ([PQR])+?
Answer - 28 : -
Both are matching PQR ,
-([PQR]+) put PQR saved in first back reference.
-([PQR])+ , first time P was saved , second time Q was saved and third time R was saved. + causes the pair of parenthesis to repeat three times.
Question - 29 : - What is the namespace represented the Regular expressions in C#.NET?
Answer - 29 : -
System.Text.RegularExpressions.Regex.
Question - 30 : - What is character class subtraction in Regular expressions?
Answer - 30 : -
Want to exclude set of character from matched text then use character class subtraction.
syntax : [Base_group -[Exclude_group]]
[0-5-[23]]
given input data array is {"12","145",""1054}
output is array is {"145",""1054} 2 excluded so that "12" not getting selected.