PrepAway - Latest Free Exam Questions & Answers

(Line numbers are included for reference only.) 01 bool…

You are developing a C# application that has a requirement to validate some string input data by using the
Regex class. The application includes a method named ContainsHyperlink. The ContainsHyperlink()
method will verify the presence of a URI and surrounding markup. The following code segment defines the
ContainsHyperlink() method. (Line numbers are included for reference only.)
01 bool ContainsHyperlink(string inputData)
02 {
03 string regExPattern = “href\\\\s*=\\\\s*(?:\\”(?<1>[^\\”]*)\\”|(?<1>\\\\S+))”;
04
05 return evaluator.IsMatch(inputData);
06 }
The expression patterns used for each validation function are constant. You need to ensure that the expression
syntax is evaluated only once when the Regex object is initially instantiated. Which code segment should you
insert at line 04?

PrepAway - Latest Free Exam Questions & Answers

A.
var evaluator = new Regex(regExPattern, RegexOptions.CultureInvariant);

B.
var evaluator = new Regex(inputData);

C.
var assemblyName = “Validation”;
var compilationInfo = new RegexCompilationInfo(inputData,
RegexOptions.IgnoreCase, “Href”, assemblyName, true);
Regex.CompileToAssembly(new[] { compilationInfo }, new AssemblyName
(assemblyName));
var evaluator = new Regex(regExPattern, RegexOptions.CultureInvariant);

D.
var evaluator = new Regex(regExPattern, RegexOptions.Compiled);

Explanation:
RegexOptions.Compiled – Specifies that the regular expression is compiled to an assembly.This yields
faster execution but increases startup time.This value should not be assigned to the Options property when
calling the CompileToAssembly method. http://msdn.microsoft.com/en-us/library/
system.text.regularexpressions.regexoptions.aspx
Additional info http://stackoverflow.com/questions/513412/how-does-regexoptions-compiled-work


Leave a Reply